java怎么把字符串写到文件里去?
发布网友
发布时间:2022-05-11 00:03
我来回答
共1个回答
热心网友
时间:2023-11-18 00:44
String s = "akjibuvuvu";
FileWriter fw = null;
File f = new File("a.txt");
try {
if(!f.exists()){
f.createNewFile();
}
fw = new FileWriter(f);
BufferedWriter out = new BufferedWriter(fw);
out.write(s, 0, s.length()-1);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("end");