aspose file tools*
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 Spring in Action this week in the Spring 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: 16145
    
  21

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.
 
wood burning stoves
 
subject: Unable to create/find new file