📄 driver.java
字号:
import java.io.*;/** Program to create a new file, called example.txt (Figure 13.6) * Author: David Riley * Date: January, 2005 */public class Driver { public Driver() { try{ File file; boolean createOK; file = new File( "example.txt" ); if ( file.exists() ) { if ( file.isDirectory() ) { System.out.println( file.getAbsolutePath() + " is a directory. No file created."); } else { boolean deleteOK = file.delete(); if ( deleteOK ) { System.out.println("Existing file deleted."); createOK = file.createNewFile(); if ( createOK ) { System.out.println("File created. "); } else { System.out.println( "Unable to create file " + file.getAbsolutePath() ); } } else { System.out.println( "Unable to delete file " + file.getAbsolutePath() ); } } } else { // file doesn't exist createOK = file.createNewFile(); if ( createOK ) { System.out.println("File created. "); } else { System.out.println( "Unable to create file " + file.getAbsolutePath() ); } } } catch (IOException e) { System.out.println( "I/O error occured"); } } /** pre: relativePath is a file name for a file relative to the * folder that contains this class * post: result is the complete path name associated with relativePath */ private String completePath(String relativePath) throws IOException { java.net.URL url = getClass().getResource(relativePath); if (url == null) throw new IOException("invalid relative file name"); else return url.getPath(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -