hadoop 在hdfs中读写文件

写文件:

 

  //指定configuration Configuration config = new Configuration(); String time = String.valueOf(end-start); FileSystem fs = FileSystem.get(URI.create("ListStatus"),config); OutputStream out = fs.create(new Path("/user/student/data/time.txt")); out.write(time.getBytes());

 

读文件:

 

//指定configuration Configuration config = new Configuration(); //定义一个DataInputStream FSDataInputStream indic = null; ArrayList dictionary = new ArrayList(); FileSystem fs = FileSystem.get(URI.create("ListStatus"),config); indic = fs.open(new Path("dic/xxx.txt")); String t = indic.readLine(); while (t != null) { dictionary.add(t); t = indic.readLine(); }

 

你可能感兴趣的:(hadoop 在hdfs中读写文件)