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文件成功!”);
}

}

7/24

 

 

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(“下载完成”);
}
}

7/24

 

原创文章,作者:506227337,如若转载,请注明出处:https://blog.ytso.com/276771.html

(0)
上一篇 2022年7月24日
下一篇 2022年7月25日

相关推荐

发表回复

登录后才能评论