Hi HaoZhe,
I use different thread for bluetooth connection & file creation.
And I am talking about local file via JSR 75 File Connection API.
I never get any error/exception.
The following is the code fragment of my application. The code works fine event the exists method of File Connection class return true
(i.e:- file created), but I am unable to find it at file system.
The code fragment as,
final byte[] data = "It is my just a test data".getBytes(); //It is the data which is comes from another bluetooth device
final String fName = "file:///root1/test.txt"; //The file I want to create at my file system(i.e:- root1 folder in my file system)
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()
And for more information you check my yesterday's post
Unable to create file