java - 将常规数据保存到文件

标签 java file

我是java新手! 我使用此代码将数据写入 .txt 文件:

try { 
String content = "This is the content to write into file";
File file = new File("/users/mkyong/filename.txt");

// if file doesnt exists, then create it

if ( !file.exists() ) {
    file.createNewFile();
}
FileWriter fw = new FileWriter( file.getAbsoluteFile() );
BufferedWriter bw = new BufferedWriter( fw );
bw.write( content );
    bw.NewLine();
bw.close();
System.out.println("Done");
} catch (IOException e) {
e.printStackTrace();
}

名字姓氏注册号

最大

1238

我想将每个数据存储在其名称下方:

我想点赞:

FName LName Reg_Num

乔最大 1238

谢谢!

最佳答案

该代码应将“This is the content to write into file”输出到文本文件中。这些名字从何而来?

用于 Java 制表 see this topic .

关于java - 将常规数据保存到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13975060/

相关文章:

java - 获取 double 的十进制数

java - 在 Android 中使用外部类从文件中写入/读取?

java - 为什么java在我的资源文件夹中找不到该文件?

c - C中的递归子目录处理

java - 如何从部署在服务器上的 Java Web 服务访问本地文件?

java - 如何将参数传递给 Ant <taskdef> 自定义 Java 类

JAVA返回父对象——继承中的继承——Builder模式

java - 是否可以将 Xamarin.forms 代码作为库添加到现有的 native Android Studio 应用程序中?

java - 容器组件如何

image - Flutter - 将图像上传到 Firebase 存储