在某位置建立*.txt文本,复制代码,测试一下输出“123”
public class Test {
public static void rwFile(){
FileWriter fw = null;
try {
fw = new FileWriter("C:\\text.txt", true);//路径一定要用"\\"
fw.write("123");//这里向文件中输入结果123
fw.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fw != null) {
try {
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
rwFile();
}
}