hadoop中关于文件操作类基本上全部是在org.apace.hadoop.fs包中,这些api能够支持的操作包含:打开文件,读写文件,删除文件等
public static void uploadLocalFile2HDFS(String s,String d)
{
Configuration conf=new Configuration();
FileSystem hdfs=FileSystem.get(config);
Path src=new Path();
hdfs.copyFromLocalFile(src,dst);
hdfs.close();
}
public static void createNewHDFSFile(String toCreateFilePath,String content){
Configuration config=new Configuration();
FileSystem hdfs=FileSystem.get(config);
FSDataOutputStream os=hdfs.create(new Path(toCreateFilePath));
os.write(content.getBytes("UTF-8"));
os.close();
hdfs.close();
}