Hi, I am usign netbeans 6.7.1 IDE and my sdk is java 6 update 14. I dont know why in FileConnection API I cant find he built in method create, mkdir, close and etc.
Because I've tried this example.
public void createFile() {
try {
FileConnection filecon = (FileConnection)
Connector.open("file:///SDCard/mynewfile.txt");
// Always check whether the file or directory exists.
// Create the file if it doesn't exist.
if(!filecon.exists()) {
filecon.create();
}
filecon.close();
} catch(IOException ioe) {
}
}
and it seems that the compiler cannot find the method exists(), create() and close(). But I can use the import javax.microedition.io.*; which means I am using JSR 75 API. So I am wondering why I cant use this methods. because i need this.
And also another question I used Nokia 6500 slide S40 OS and I install this, please refer to this code fragment:
OutputConnection connection = (OutputConnection)
Connector.open("file://c:/myfile.txt;append=true", Connector.WRITE );
OutputStream out = connection.openOutputStream();
PrintStream output = new PrintStream( out );
output.println( "This is a test." );
out.close();
connection.close();
Alert alert = new Alert("Completed", "Data Written", null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
}
catch( ConnectionNotFoundException error )
{
Alert alert = new Alert(
"Error", "Cannot access file.", null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
}
catch( IOException error )
{
Alert alert = new Alert("Error", error.toString(), null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
}
When I tried to write a file in my phone, I got java.lang.SecurityException. I want to know the reason why? And is it possible in Nokia 6500 slide S40 to do this? like create directory? move and delete files? Thanks And by the way Nokia 6500 slide supports JSR 75. Any help will be greatly appreciated. Thank you so much.

Reply With Quote

