[英]How to Write/Read in JavaFX with Gluon Plugin
I am trying to write/read files in JavaFX while using the Gluon plugin, and I am not having any luck.我正在尝试在使用 Gluon 插件时在 JavaFX 中写入/读取文件,但我没有任何运气。 If i run the program as a Desktop App, it works fine, I've even used the same functions in Android IDE and it works fine, however if I send the program to my phone with Gluon, it does not work.如果我将程序作为桌面应用程序运行,它运行良好,我什至在 Android IDE 中使用了相同的功能并且运行良好,但是如果我使用 Gluon 将程序发送到我的手机,它就不起作用。 I wanting to know how to save/read to files in Gluon, and what have I done wrong, and why does it work as Desktop and on Android but not Gluon.我想知道如何在 Gluon 中保存/读取文件,以及我做错了什么,以及为什么它可以作为桌面和 Android 而不是 Gluon。 The two fcns I used are:我使用的两个 fcns 是:
public void writeToFile() {
try {
FileOutputStream f = new FileOutputStream("Meal1_Protein.txt");
f.write(choice.getBytes()); //Choice is input from a dropdown
f.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Toast toast = new Toast(choice);
toast.show();
}
public void readFromFile(){
try {
FileInputStream f = new FileInputStream("Meal1_Protein.txt");
InputStreamReader is = new InputStreamReader(f);
BufferedReader br = new BufferedReader(is);
StringBuffer buff = new StringBuffer();
String lines;
while((lines = br.readLine())!=null){
buff.append(lines);
buff.append("\n");
}
carbInput.setText(buff.toString()); // inserting into a txtfield
//to see if it I can read strings back in.
Toast toast = new Toast(buff.toString());
toast.show();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} }
Please using StorageService .请使用StorageService 。
The storage service provides access to the private and public storage locations for the application offered by the native platform.存储服务提供对本地平台提供的应用程序的私有和公共存储位置的访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.