如何将字符串保存到java中的.txt文件中

时间:2014-03-10 12:20:39

标签: java save

我完成了一个应用程序并测试了所有功能,并且它们正在运行。但是,输入数据的一部分应该保存到.txt文件中。我把它放在一个字符串里但是我在这个区域有点超出我的深度并且不知道如何将它保存到我的PC上的驱动器中。任何帮助表示赞赏。代码位于以下链接:http://sharetext.org/fSy2

1 个答案:

答案 0 :(得分:0)

试试这个:

public static void main(String args[])throws IOException {

  File file = new File("Hello1.txt");
  // creates the file
  file.createNewFile();
  // creates a FileWriter Object
  FileWriter writer = new FileWriter(file); 
  // Writes the content to the file
  writer.write("This\n is\n an\n example\n"); 
  writer.flush();
  writer.close();
}

详细了解here

相关问题