Ecriture dans un fichier en J2ME
Bonjour,
j'essaye d'écrire dans un fichier texte grâce à un programme J2me, voila le programme que j'utilise:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| //Ecriture dans un fichier
private void ecriture(){
System.getProperty("microedition.io.file.FileConnection.version");
try
{ System.out.println("test1");
OutputConnection connection = (OutputConnection)
Connector.open("file:///c:/test.txt", Connector.WRITE );
System.out.println("test2");
OutputStream out = connection.openOutputStream();
System.out.println("test3");
PrintStream output = new PrintStream( out );
System.out.println("test4");
output.println( "This is a test." );
System.out.println("test5");
out.close();
System.out.println("test6");
connection.close();
System.out.println("écriture réussie");
Alert alert = new Alert("Completed", "Data Written", null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
_display.setCurrent(alert);
}
catch( ConnectionNotFoundException error )
{System.out.println("fichier non trouvé");
Alert alert = new Alert(
"Error", "Cannot access file.", null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
_display.setCurrent(alert);
}
catch( IOException error )
{System.out.println("fichier non trouvé2");
Alert alert = new Alert("Error", error.toString(), null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
_display.setCurrent(alert);
}
} |
j'obtiens l'erreur suivante:
Code:
java.io.IOexception: Root is not accessible
L'erreur, d'après moi, viendrait de la syntaxe du chemin d'accès au fichier mais je ne sais pas comment résoudre le problème. Auriez-vous une idée svp?
merci d'avance.