Lab 20
Lab 20
Name: Zhenan Li
For your own convenient reference – You should first save/rename this
document using the naming convention MUid_Exercise20.docx (example:
raodm_Exercise20.docx) prior to proceeding with this exercise.
Fill in answers to all of the questions. For some of the questions you can simply copy-paste
appropriate text from Eclipse output into this document. You may discuss the questions or
seek help from your neighbor, TA, and/or your instructor.
Exercise: Briefly (2-to-3 sentences each) respond to the following questions regarding generic
concepts of file paths.
1. When we develop programs using files, we typically prefer to use relative paths. Why?
Because relative paths are preferred, using absolute paths may be incompatible because
Page 1 of 5
DUE DATE: By the end of your lab session
the user will place the java file in a different location on the computer.
2. Complete the following table to illustrate some of the general relative paths using a
suitable sequence of ./ or ../:
Description Relative path
Present working directory (pwd) ./
The parent directory ../
The grandparent directory ../../
The great-grandparent directory ../../../
A subdirectory called sub under pwd ./sub
b. Assume the present working directory in hw1. Assume you have to call the
following copy method:
class FileUtils {
/**
* Copies contents of a given source file to given destination file.
* @param srcFile The source file to be copied.
* @param destFile The duplicate file to be created.
*/
public static void copy(String srcPath, String destPath);
}
Illustrate a call (i.e., 1-line of code) to the above copy method to copy a file
named main.dat from the cse278 directory to a file named
main_copy.dat in the cse381 directory.
FileUtils.copy(“../cse278/main.dat”, “../../cse31/main_copy.dat”);
Background: Files are used to store different types of data on a storage medium. The contents of
a file are classified into two main categories, namely text files and binary files. Binary files store
Page 2 of 5
DUE DATE: By the end of your lab session
bytes (a byte is 8-bits) of data while text files operate with characters. In Java a byte can have the
value -128–+127. In Java, a character occupies 2-to-4 bytes, depending on the encoding of
characters. Text files, typically contain bytes with the value in the range 32–127, also called as 7-
bit ASCII characters.
Exercise: In this part of the exercise, we will be reviewing some of the basic concepts of text
and binary files.
Page 3 of 5
DUE DATE: By the end of your lab session
Background: Recollect that, binary files are not human-readable and require a special program
to create and manipulate binary files. Hence, binary files are typically created from text data that
is either entered by the user or read from a file. This would be the case immaterial of whether a
GUI is used. A similar approach is used for binary files associated with databases or even
spreadsheets.
Page 4 of 5
DUE DATE: By the end of your lab session
Exercise: You will be submitting the following files via the Canvas CODE plug-in:
1. This MS-Word document saved as a PDF file – Only submit PDF file.
2. The Java source file Employee.java that you modified in this exercise.
Ensure you actually complete the submission on Canvas by verifying your submission (after you
submit)
Page 5 of 5