用java编写什么代码,才可以把键盘输入的内容存储到文件中呢?
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);
}
}
}
输出的文件在工作空间的工程文件夹里
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);
}
}
}
输出的文件在工作空间的工程文件夹里
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询