1. What will be the output of the following code?
a. Explain your answer per line
import java.io.File; //imports the File class
public class Attributes
{
public static void main(String[] args)
{
File file = new File("src/Attributes.java"); //Creating an object of a new file
System.out.println("exists: "+file.exists()); //tests if the file exists
System.out.println("path: "+file.path()); //returns the pathname of the file
System.out.println("length: "+file.length()); //Returns the size of the file in bytes
System.out.println("isDirectory: "+file.isDirectory()); //tests if the file is a directory or not
System.out.println("isFile: "+file.isFile()); //tests whether the file is a regular file or not
System.out.println("canRead: "+file.canRead()); //tests whether the file is readable or not
}
}
2. In your IDE, follow the instruction to produce the
“The journey of a thousand miles begins with a single step” output.
a. Save this “The journey of a thousand miles begins with a single step” to
SampleText.txt inside your eclipse project folder.
b. Write the correct code to generate the given output using try catch with exception.
c. Make sure that you split your screen showing the correct code and the console
output. (paste your solution with output here in console)
Code:
3. Create an OutputFile.java that will display the length, the specific path, and the number of
words of the SampleText.txt then store and display it using SampleOuputText.txt. Use a try
catch with exception. (paste your solution with output here in console and text file)
4. Append a new row data with the text ”This little light of mine, I’m gonna let it shine” in
SampleText.txt then follow the instruction in number 3. Take note that it should contain
additional row data. (paste your solution with output here in console and text file)