⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filewritertest.java

📁 java I/0流的代码程序
💻 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 + -