package hdfs;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.Before;
import org.junit.Test;
public class mycode {
public static void main(String[] args) throws Exception {
Configuration conf=new Configuration();
conf.set("fs.replication","2");
conf.set("fs.blocksize", "64m");
FileSystem fs=FileSystem.get(new URI("hdfs://192.168.33.11:9000/"), conf, "root");
fs.copyFromLocalFile(new Path("E:/download/yyy.txt"),new Path("/"));
fs.close();
}
FileSystem fs = null;
@Before
public void init() throws Exception{
Configuration conf = new Configuration();
conf.set("dfs.replication", "2");
conf.set("dfs.blocksize", "64m");
fs= FileSystem.get(new URI("hdfs://192.168.33.11:9000/"), conf, "root");
}
@Test
public void TestGet() throws IllegalArgumentException, IOException{
fs.copyToLocalFile(new Path("/b.log"), new Path("E:/download/hello"));
fs.close();
}
@Test
public void TestRename() throws IOException{
fs.rename(new Path("/yyy.txt"),new Path("/xx/gg.blog"));
fs.close();
}
@Test
public void TestDlete() throws IllegalArgumentException, IOException{
fs.delete(new Path("/user/a.txt"), true);
fs.close();
}
@Test
public void TestMkdir() throws Exception{
fs.mkdirs(new Path("/xx/yy/zz"));
fs.close();
}
@Test
public void RequstDocument() throws FileNotFoundException, IllegalArgumentException, IOException{
FileStatus[] documents = fs.listStatus(new Path("/"));
System.out.println("我在这里");
for(FileStatus status:documents){
System.out.println("文件全路径:"+status.getPath());
System.out.println(status.isDirectory()?"这是文件夹":"这是文件");
System.out.println("块大小:"+status.getBlockSize());
System.out.println("文件长度:"+status.getLen());
System.out.println("副本数量:"+status.getReplication());
System.out.println("--------------------------------");
}
}
}
大数据学习:eclipse客户机和hadoop集群通信,增删查改等基本操作
最新推荐文章于 2024-04-29 01:52:17 发布