Welcome Guest | Sign in | Register
File - Discussion Page For Q.2722 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > File > Questions and Answers

Q: What will be the result of compiling and run the following code:

public class Test {
public static void main(String... args) throws Exception {
File file = new File("test.txt");
System.out.println(file.exists());
file.createNewFile();
System.out.println(file.exists());
}
}
A. True true B. False true
C. False true D. None of the above

Answer and Explanation

Answer:False true

Explanation:
creating a new instance of the class File, you're not yet making an actual file, you're
just creating a filename.
So file.exists() return false.
createNewFile() method created an actual file.so file.exists() return true.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.