2009年2月17日 星期二

第145題

Given that the current directory is empty, and that the user has read and write permissions, and the following:
11. import java.io.*;
12. public class DOS{
13. public static void main(String[] args){
14. File dir = new File("dir");
15. dir.mkdir();
16. File f1 = new File(dir, "f1.txt");
17. try{
18. f1.createNewFile();
19. }catch(IOException e){;}
20. File newDir = new File("newDir");
21. dir.renameTo(newDir);
22. }
23. }

Which statement is true?
A. Compilation fails.
B. The file system has a new empty directory named dir.
C. The file system has a new empty directory named newDir.
D. The file system has a directory named dir, containing a file f1.txt.
E. The file system has a directory named newDir, containing a file f1.txt.
答案:E
參考:10-3 File類別

------------------------------------------

14. File dir = new File("dir"); //命名一個檔名為dir
15. dir.mkdir(); // 用此名建立一個目錄
16. File f1 = new File(dir, "f1.txt"); // 在dir 下面開一個 f1.txt
18. f1.createNewFile(); // 建立檔案.
20. File newDir = new File("newDir"); //命名一個檔名為 newDir
21. dir.renameTo(newDir); //把原來的 dir 改成 newDir.

沒有留言:

張貼留言