자격증/OCJP_ExamA

QUESTION 27

IT grow. 2018. 7. 1. 00:36
반응형

Given that the current directory is empty, and that the user has read and write permissions, and the following: 

 

1. import java.io.*; 

2. public class DOS { 

3.     public static void main(String[] args) { 

4.         File dir = new File("dir"); 

5.         dir.mkdir(); 

6.         File f1 = new File(dir, "f1.txt"); 

7.         try { 

8.             f1.createNewFile(); 

9.         } catch (IOException e) { ; } 

10.         File newDir = new File("newDir"); 

11.         dir.renameTo(newDir); 

12.     } 

13. } 

 

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.


Solution :  E


11 line 에 dir.renameto(newDir)를 통해 이름을 재정의 합니다 . 그리고 6line에서 "f1.txt"을 지정하여 새로운 인스턴스를 생성한 것을 확인 하실 수있습니다

반응형