繁体   English   中英

如何使用 Gluon 插件在 JavaFX 中写入/读取

[英]How to Write/Read in JavaFX with Gluon Plugin

我正在尝试在使用 Gluon 插件时在 JavaFX 中写入/读取文件,但我没有任何运气。 如果我将程序作为桌面应用程序运行,它运行良好,我什至在 Android IDE 中使用了相同的功能并且运行良好,但是如果我使用 Gluon 将程序发送到我的手机,它就不起作用。 我想知道如何在 Gluon 中保存/读取文件,以及我做错了什么,以及为什么它可以作为桌面和 Android 而不是 Gluon。 我使用的两个 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();
}

}

请使用StorageService

存储服务提供对本地平台提供的应用程序的私有和公共存储位置的访问。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM