filewritertest.java
来自「java I/0流的代码程序」· Java 代码 · 共 37 行
JAVA
37 行
import java.io.*;import javax.swing.*;class FileWriterTest{ public static void main(String argv[]) { File file = null; FileWriter writeFile = null; BufferedWriter out = null; String name = JOptionPane.showInputDialog("Input the .txt file name"); if(name!=null) { try { file = new File(name + ".txt"); //创建文件对象file file.createNewFile(); //创建新的文件 } catch (IOException e) {} } else System.out.println("Can not create a file!"); String content = JOptionPane.showInputDialog("Please input the contents of this file:"); try { writeFile = new FileWriter(file); } catch(IOException e){} out = new BufferedWriter(writeFile); try { out.write(content); out.flush(); out.close(); writeFile.close(); } catch(IOException e){} }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?