经过种种调试,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(“下载完成”);
}
}
原创文章,作者:506227337,如若转载,请注明出处:https://blog.ytso.com/tech/java/276771.html