-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShowFile.java
More file actions
42 lines (38 loc) · 1.12 KB
/
Copy pathShowFile.java
File metadata and controls
42 lines (38 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* Display a text file.
To use this program, specify the name of the file that you want to see.
For example, to see a file called TEST.TXT, use the following command line.
java ShowFile TEST.TXT
*/
import java.io.*;
class ShowFile {
public static void main(String[] args)
{
int i;
FileInputStream fin;
// First make sure that a file has been specified.
if (args.length != 1) {
System.out.println("Usage: ShowFile File");
return;
}
try {
fin = new FileInputStream(args[0]);
} catch(FileNotFoundException exc) {
System.out.println("File Not Found");
return;
}
try {
// Read bytes until EOF is encountered.
do {
i = fin.read();
if (i != -1) System.out.print((char) i);
} while (i != -1);
} catch(IOException exc) {
System.out.println("Error reading file.");
}
try {
fin.close();
} catch(IOException exc) {
System.out.println("Error closing file.");
}
}
}