这是我用来编写文件的示例片段
hdfs
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
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 org.apache.hadoop.util.Progressable;
public class WriteFileToHDFS {
public static void main(String[] args) throws IOException, URISyntaxException
{
System.setProperty("hadoop.home.dir", "/");
System.setProperty("HADOOP_USER_NAME", "hdfs");
//1. Get the instance of COnfiguration
Configuration configuration = new Configuration();
//2. Create an InputStream to read the data from local file
InputStream inputStream = new BufferedInputStream(new FileInputStream("/Users/rabbit/Research/hadoop/sample_files/TAO.mp4"));
//3. Get the HDFS instance
FileSystem hdfs = FileSystem.get(new URI("hdfs://192.168.143.150:9000"), configuration);
//4. Open a OutputStream to write the data, this can be obtained from the FileSytem
OutputStream outputStream = hdfs.create(new Path("hdfs://192.168.143.150:9000/filestore/TAO.mp4"),
new Progressable() {
@Override
public void progress() {
System.out.println("....");
}
});
try
{
IOUtils.copyBytes(inputStream, outputStream, 4096, false);
}
finally
{
IOUtils.closeStream(inputStream);
IOUtils.closeStream(outputStream);
}
}
}
我希望这可以写成
/data/hadoop-data/dn/current/blk_1073741869
而是写为
/data/hadoop-data/dn/current/BP-1308070615-172.22.131.23-1533215887051/current/finalized/subdir0/subdir0/blk_1073741869
BP-1308070615-172.22.131.23-1533215887051/current/finalized/subdir0/subdir0
-生成了此路径?