在java中从控制台输入一些字符串,并将该类信息保存到日志文件中,怎么做啊????
1个回答
展开全部
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class FileWrite {
public void fileWrite() throws IOException{
Scanner scanner = new Scanner(System.in);
System.out.println("输入一些东西:");
String string = scanner.next();
File file = new File("C://","Example.txt");
if(!file.exists()){
file.createNewFile();
}
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(string);
fileWriter.close();
}
public static void main(String[] args) throws IOException{
FileWrite fWrite = new FileWrite();
fWrite.fileWrite();
}
}
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class FileWrite {
public void fileWrite() throws IOException{
Scanner scanner = new Scanner(System.in);
System.out.println("输入一些东西:");
String string = scanner.next();
File file = new File("C://","Example.txt");
if(!file.exists()){
file.createNewFile();
}
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(string);
fileWriter.close();
}
public static void main(String[] args) throws IOException{
FileWrite fWrite = new FileWrite();
fWrite.fileWrite();
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询