forked from patniemeyer/learningjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListIt.java
More file actions
30 lines (27 loc) · 923 Bytes
/
Copy pathListIt.java
File metadata and controls
30 lines (27 loc) · 923 Bytes
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
import java.io.*;
public class ListIt
{
public static void main ( String args[] ) throws Exception {
File file = new File( args[0] );
if ( !file.exists() || !file.canRead( ) ) {
System.out.println( "Can't read " + file );
return;
}
if ( file.isDirectory( ) ) {
String [] files = file.list( );
for (int i=0; i< files.length; i++)
System.out.println( files[i] );
}
else
try {
Reader ir = new InputStreamReader( new FileInputStream( file ) );
BufferedReader in = new BufferedReader( ir );
String line;
while ((line = in.readLine( )) != null)
System.out.println(line);
}
catch ( FileNotFoundException e ) {
System.out.println( "File Disappeared" );
}
}
}