SCJP題庫第151題

Given that the current directory is empty, and that the user has read and write privileges to the current directory, and the following:
1. import java.io.*;
2. public class Maker{
3.   public static void main(String args){
4.     File dir = new File("dir");
5.     File f = new File(dir, "f");
6.   }
7. }
Which statement is true?


A. Compilation fails.
B. Nothing is added to the file system.
C. Only a new file is created on the file system.
D. Only a new directory is created on the file system.
E. Both a new file and a new directory are created on the file system.

Ans: B

解說:
4/5行只是宣告目錄、檔案
真正建立檔案的方法是createNewFile(),例子如145

Comments

Popular posts from this blog

Android-使用webview在V3版的Google地圖GPS定位