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

📄 writecharacters.java

📁 Java Classic Examples是我买的两本书:《JAVA经典实例》和《java入门经典源代码》里边附送光盘里带的源码
💻 JAVA
字号:
// Appending data to a file
import java.io.*;

class WriteCharacters
{
  public static void main(String[] args)
  {
    try
    {
      String dirName = "c:\\JunkData\\"; // Directory for the output file
      String fileName = "Proverbs.txt";  // Name of the output file 
      File output = new File(dirName, fileName);
      output.createNewFile();            // Create a new file if necessary

      if(!output.isFile())               // Verify we have a file
      {
        System.out.println("Creating " + output.getPath() + " failed.");
        return;
      }

      BufferedWriter out = new BufferedWriter(
                                new FileWriter(output.getPath(), true));

      String[] sayings = { "Indecision maximixes flexibility.",
                           "Only the mediocre are always at their best.",
                           "A little knowledge is a dangerous thing.",
                           "Many a mickle makes a muckle.",
                           "Who begins too much achieves little.",
                           "Who knows most says least.",
                           "A wise man sits on the hole in his carpet."};

      // Write the proverbs to the file preceded by the string length
      for(int i = 0; i < sayings.length; i++)
      {
        out.write(sayings[i].length() + sayings[i]);
      }
      out.close();
    }
    catch(IOException e)
    {
      System.out.println("Error writing the file " + e);
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -