Mkdir.java:
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class Mkdir {
public static void main(String[] args) throws Exception {
FileSystem fs = FileSystem.get(new URI("hdfs://192.168.205.129:9000"), new Configuration(), "root");
Boolean flag = fs.mkdirs(new Path("/aa"));
if (flag) {
System.out.println("创建目录成功");
} else {
System.out.println("创建目录失败");
}
System.out.println("ok");
}
}
Delete.java:
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class Delete {
public static void main(String[] args) throws Exception {
FileSystem fs = FileSystem.get(new URI("hdfs://192.168.205.129:9000"), new Configuration(), "root");
Boolean flag = fs.delete(new Path("hdfs://192.168.205.129:9000/aa"), true);
if (flag) {
System.out.println("删除成功");
} else {
System.out.println("删除失败");
}
}
}
Upload.java:
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
public class Upload {
public static void main(String[] args) throws Exception {
FileSystem fs = FileSystem.get(new URI("hdfs://192.168.205.129:9000"), new Configuration(), "root");
InputStream in = new FileInputStream("/home/hong/test.txt");
OutputStream out = fs.create(new Path("/aa/test1.txt"));
IOUtils.copyBytes(in, out, 4096, true);
System.out.println("上传成功。。。");
}
}
Download.java:
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
public class Download {
public static void main(String[] args) throws Exception {
FileSystem fs = FileSystem.get(new URI("hdfs://192.168.205.129:9000"), new Configuration());
InputStream in = fs.open(new Path("/aa/test.txt"));
OutputStream out = new FileOutputStream("/home/hong/111.txt");
IOUtils.copyBytes(in, out, 4096, true);
System.out.println("下载成功。。。");
}
}