package hadoop_study;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;
import org.junit.Test;
public class TestHDFS {
public void readFile() throws Exception {
URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
URL url = new URL("hdfs://192.168.2.61:8020/hello.txt");
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
byte[] buf = new byte[is.available()];
is.read(buf);
is.close();
String str = new String(buf);
System.out.println(str);
}
public static void main(String[] args) {
TestHDFS th = new TestHDFS();
try {
th.readFile();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}