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

📄 checkforwrite.java

📁 《A first book of java》by Gary J.Bronson 北大出版社
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -