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

📄 testdatastream.java

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

public class TestDataStream
{
  public static void main(String[] args)
  {
    String myStr = new String("Garbage in, garbage out");
    String dirName = "C:/MyData";   // Directory name

    try
    {
      File dir = new File(dirName);  // File object for directory

      if(!dir.exists())              // If directory does not exist
        dir.mkdir();                 // ...create it
      else
        if(!dir.isDirectory())
          {
          System.err.println(dirName + " is not a directory");
          return;
        }

      File aFile = new File(dir, "data.txt"); 
      aFile.createNewFile();         // Now create a new file if necessary

      // Create the byte output stream
      DataOutputStream myStream = new DataOutputStream(
                                    new FileOutputStream(aFile));
      myStream.writeChars(myStr);    // Write the string to the file
    }
    catch(IOException e)
    {
      System.out.println("IO exception thrown: " + e);
    }
  }
}

⌨️ 快捷键说明

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