import java.io.FileOutputStream;
import java.io.OutputStream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
public class HadoopMain {
public static void main(String[] args) throws Exception {
//跟HDFS建立上连接,要知道NameNode的地址即可
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "org.apache.hadoop.hdfs.DistributedFileSystem");
FileSystem fileSystem = FileSystem.get(conf);
//打开一个输入流
FSDataInputStream in = fileSystem.open(new Path("/hellohdfs"));
//打开一个本地文件的输出流
OutputStream out = new FileOutputStream("d://outhdfs.txt");
//拷贝in -> out
IOUtils.copyBytes(in, out, 1024,true);
}
}