Write a text file in Codename One

43 Views Asked by At

I cannot find any mention of writing strings to a text file in Codename One. I need to create and maintain a "directory" of saved image groups so I can retrieve the name of the group and then retrieve the images by their saved name in ImageViewer. Has anyone developed an imitation of the Java FileWriter?

1

There are 1 best solutions below

1
Shai Almog On

Codename One has a Writer class but not a FileWriter since the file system is a bit different from the one on the OS.

You can just use FileSystemStorage or Storage to write a text file just like you can in Java SE using OutputStream or Writer. E.g.:

FileSystemStorage fs = FileSystemStorage.getInstance();
String fileName = fs.getAppHomePath() + "my_file.txt";
try(Writer w = new OutputStreamWriter(fs.openInputStream(fileName))) {
    w.write("This is the text in the file");
}