我在 Codename One 中找不到任何关于将字符串写入文本文件的内容。我需要创建并维护已保存图像组的“目录”,以便我可以检索组的名称,然后通过 ImageViewer 中保存的名称检索图像。有人开发过 Java FileWriter 的仿制品吗?
Codename One 有一个
Writer
类,但没有 FileWriter
,因为文件系统与操作系统上的有点不同。
您可以使用
FileSystemStorage
或 Storage
来编写文本文件,就像在 Java SE 中使用 OutputStream
或 Writer
一样。例如:
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");
}