CN1:写入在旧的GUI构建器中创建的文件并读取

时间:2018-12-20 08:16:54

标签: codenameone

因此,我在旧的GUI构建器中的数据部分下创建了一个.txt文件。如何向该文件添加文本并阅读?

2 个答案:

答案 0 :(得分:1)

这是资源文件,而不是旧的GUI构建器。

您无法修改资源文件中的文件,因为它们无法写入。此外,这些文件打包在JAR / APP中,这是设备上的只读文件。

您可以将文件提取到存储/文件系统中的可写位置,并在那里使用文件。

您可以详细了解Storage / FileSystemStorage here

答案 1 :(得分:0)

感谢您的回复@Shai Almog。

我用Preferences API解决了。由于我需要保存令牌,因此这是最好的方法:

// save a token to storage
Preferences.set("token", myToken);

// get the token from storage or null if it isn't there
String token = Preferences.get("token", null);