1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.Writer;
public class Main { public static void main(String[] args) { String str = "Hello World"; Writer fw = null; try { File file = new File("D:\\hello.txt"); if (!file.exists()) { file.createNewFile(); } fw = new FileWriter("D:\\hello.txt"); fw.write(str); fw.flush(); if (fw != null) { fw.close();
} } catch (IOException e) { e.printStackTrace(); } } }
|