📄 filewritertest.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -