将字符串hello world写入到文本中,并且保存到指定的磁盘中,在这里使用到了字符输入流FileWriter指定路径还使用了writer的方法写入字符串,使用完之后记得close()关闭字符输入流。
public static void main(String[] args) {
String str="hello world";
FileWriter fw=null;
try {
fw=new FileWriter("E:\\hello.txt");
fw.write(str);
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}