This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java Micro Edition and the fly likes Unable to create/find new file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Unable to create/find new file" Watch "Unable to create/find new file" New topic
Author

Unable to create/find new file

Ritesh Chopade
Greenhorn

Joined: Oct 22, 2008
Posts: 8
Hello,
I am new to J2ME. I am developing application to download file from one mobile to another through bluetooth connection. I am working using J2ME wireless toolkit.
I receive data through bluetooth connection(from slave to master). At master device I have to create new file(if not exists) & write the data(from slave) to file.
My code works fine(without exception), but once code execute fine I am not able to see the file at root location in j2me wireless toolkit(emulator) using default color phone.
My root folder is root1. My code is as follows,


final byte[] data = "It is my just a test data".getBytes(); //Data which is comes from another blutooth device
final String fName = "file:///root1/test.txt";
new Thread(new Runnable() {

public void run() {
try{
FileConnection fc = (FileConnection) Connector.open(fName, Connector.WRITE);
System.out.println("fc.exists()(Before) : " + fc.exists() ); //It prints fc.exists()(Before) : false
if( !fc.exists() ){
fc.create();
System.out.println("fc.exists()(After) : " + fc.exists() ); //It prints fc.exists()(After) : true
OutputStream fout = fc.openOutputStream();
fout.write(data);
fout.close();
}
fc.close();
}catch(IOException ex){
ex.printStackTrace();
}
}
}).start();


Please help me.
Thanks in advance.....
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Different phones do filesystems in different ways. There's no universal standard, and as far as I know, even the existence of a filesytem is optional.

You might try doing this:

File myDirectory = new File(".");

Then display myDirectory.getAbsolutePath();

That will show you where you're starting from and how the filenames are formed on that device.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Unable to create/find new file