Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to create/find new file

 
Ritesh Chopade
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18014
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic