用java编写代码 题目是把键盘输入的内容存储到文件中

2024-12-28 23:13:51
推荐回答(1个)
回答1:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
public class Fileout1 {
public static void main(String[] args){
try {
File file = new File("File.txt");
Scanner num = new Scanner(System.in);
System.out.println("请输入要录入的内容:");
String b = num.nextLine();
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(b);
writer.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
输出的文件在工作空间的工程文件夹里