checkforwrite.java

来自「《A first book of java》by Gary J.Bronson 」· Java 代码 · 共 25 行

JAVA
25
字号
import java.io.*;
public class CheckForWrite
{
  public static void main(String[] args)
    throws java.io.IOException
  {
    String fileName = "prices.dat";
    char response;

    File outFile = new File(fileName);

      // check that the file does not already exist
    if (outFile.exists())
    {
      System.out.println("The file " + fileName + "currently exists.");
      System.out.print("Are you sure you want to write to it? Enter y or n:");
      response = (char) System.in.read();
      if (response == 'n')
        System.exit(1);
    }

     // set up the output stream and write to the file
    System.out.println("The file " + fileName + " can be written to.");
  }
}

⌨️ 快捷键说明

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