32 lines
949 B
Java
32 lines
949 B
Java
|
import org.apache.hadoop.conf.Configuration;
|
||
|
import org.apache.hadoop.fs.FSDataInputStream;
|
||
|
import org.apache.hadoop.fs.FSDataOutputStream;
|
||
|
import org.apache.hadoop.fs.FileSystem;
|
||
|
import org.apache.hadoop.fs.Path;
|
||
|
|
||
|
import java.net.URI;
|
||
|
import java.util.Scanner;
|
||
|
|
||
|
public class ReadFile {
|
||
|
public static void main(String[] args) {
|
||
|
try {
|
||
|
Scanner sc = new Scanner(System.in);
|
||
|
String filePath = '/'+sc.next();
|
||
|
FileSystem fs = FileSystem.get(new URI("hdfs://master:9000"), new Configuration());
|
||
|
|
||
|
Path srcPath = new Path(filePath);
|
||
|
|
||
|
FSDataInputStream is = fs.open(srcPath);
|
||
|
while(true) {
|
||
|
String line = is.readLine();
|
||
|
if(line == null) {
|
||
|
break;
|
||
|
}
|
||
|
System.out.println(line);
|
||
|
}
|
||
|
is.close();
|
||
|
}catch(Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
}
|