代码:
[mw_shl_code=java,true]package hdfs.operation;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class operateHdfs {
public static void main(String args[]) throws IOException {
byte[] contents = "hello world\n--created by eclipse\n".getBytes();
System.out.println("begin");
createFile("/input/first.txt", contents);
}
public static void createFile(String dst, byte[] contents) throws IOException {
Configuration conf = new Configuration();
System.out.println("-----------:" + conf);
conf.set("fs.defaultFS", "hdfs://192.168.86.133:9000"); // master
FileSystem fs = FileSystem.get(conf);
Path dstPath = new Path(dst); //
FSDataOutputStream outputStream = fs.create(dstPath);
outputStream.write(contents);
outputStream.close();
fs.close();
System.out.println("创建成功");
}
}[/mw_shl_code]
创建后显示乱码:
[root@master ~]# hadoop fs -ls /
Found 3 items
drwxr-xr-x - root supergroup 0 2017-06-07 22:30 /data
drwxr-xr-x - æÂæ supergroup 0 2017-06-09 09:53 /input
drwxr-xr-x - root supergroup 0 2017-06-08 00:55 /user
求解 owner乱码
|
|