Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.135 :

Posted: Sun Dec 16, 2012 6:21 pm
by ETS User
Answer "You can create files in any directory using File class's API." is misleading because on any platform there are places that are system protected or there are other permissions that will not allow to create new file/directory (in example: home directory of another user).

Re: About Question com.enthuware.ets.scjp.v6.2.135 :

Posted: Sun Dec 16, 2012 7:40 pm
by admin
What you say is true but the API itself poses no restrictions. For example, you can't create a file if the disk is full either but that is not what the statement implies.

HTH,
Paul.

Re: About Question com.enthuware.ets.scjp.v6.2.135 :

Posted: Tue Jul 08, 2014 8:23 am
by kannattaa
Option
Once created there is no way to change the file or directory that the File object represents.
should be matched.

This code changes the file that the File object represents:

Code: Select all

        File file1 = new File("file1.txt");
        File file2 = new File("file2.txt");
        File tempFile = new File("temp_file.txt");
        file1.renameTo(tempFile);
        file2.renameTo(file1);
        file1.delete();
Note, that "the file" term is used, not "the path to file".

Re: About Question com.enthuware.ets.scjp.v6.2.135 :

Posted: Wed Aug 16, 2017 9:47 am
by Aditya553
Please explain why option 4 is correct?
explanation given -Instances of the File class are immutable; that is, once created, the abstract pathname represented by a File object will never change

Re: About Question com.enthuware.ets.scjp.v6.2.135 :

Posted: Wed Aug 16, 2017 10:22 pm
by admin
Because as the explanation says, you can't change the File object after creation. There are no setter methods or public fields in this class. You have to create a new File object if you want to represent a different file.

Re: About Question com.enthuware.ets.scjp.v6.2.135 :

Posted: Mon Apr 12, 2021 1:19 am
by alfredo.zuloaga
why this is not consider as transverse ?
java.io.File a = new File("/");
Arrays.stream(a.list()).limit(10).forEach(System.out::println);

Re: About Question com.enthuware.ets.scjp.v6.2.135 :

Posted: Mon Apr 12, 2021 1:42 am
by admin
You are right. This question is not good. It is too vague and should be removed.
thank you your feedback!