7/24
作者:互联网
经过种种调试,Hadoop可以用了。
package hadoop;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
public class upload {
public static void main(String[] args) throws Exception{
FileSystem fs = FileSystem.get(new URI("hdfs://localhost/:8020"),new Configuration(),"root");
InputStream in = new FileInputStream("D://text.txt");
OutputStream out = fs.create(new Path("/text.txt"));
IOUtils.copyBytes(in,out,4096,true);
System.out.println("上传Hadoop文件成功!");
}
}
package hadoop;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
public class download {
public static void main(String[] args) throws Exception{
FileSystem fs = FileSystem.get(new URI("hdfs://localhost/:8020"),new Configuration());
InputStream is = fs.open(new Path("/text.txt"));
OutputStream out = new FileOutputStream("D://JAVA/text.txt");
IOUtils.copyBytes(is,out,4096,true);
System.out.println("下载完成");
}
}
标签:24,fs,java,hadoop,io,new,import 来源: https://www.cnblogs.com/duanzheng/p/16515618.html