1.本地创建一个文件,"words.txt" ,上传到hdfs: "/neusoftin" 下
package hdfs;
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;
/**
* HDFS 文件上传
* @author Administrator
*
*/
public class CreateFile {
public static void main(String[] args) throws Exception {
//设置一个配置 服务器所在 信息
Configuration conf = new Configuration();
// linux 上的 hdfs 访问 地址
conf.set("fs.defaultFS", "hdfs://master:8020");
// 从服务器 获取 hdfs 文件 操作对象
FileSystem hdfs = FileSystem.get(conf);
//找到上传的 文件
byte[] buf = ("BEIJING, April 14 (Xinhua) According to Sputnik's report on April 14, the Russian " +
"side said that two Ukrainian combat helicopters entered Russian airspace and attacked " +
"residential buildings. At present, the Ukrainian side has not yet responded to this " +
"news. This is the second time since the outbreak of the Russian-Ukrainian conflict " +
"that Russia has claimed that Ukrainian helicopters have entered Russian airspace." +
"According to reports, the Russian investigation committee said that Ukrainian helicopters" +
" carried out at least six attacks on the residential building in Klimovo. The Committee " +
"has launched a criminal investigation into the attack." +
"Not long ago, Alexander Kuznetsov, assistant minister of health of Russia, said that " +
"the Ukrainian army attacked Bryansk, causing seven injuries, and all the injured were " +
"hospitalized." +
"For th