Eclipse-HadoopAPI开发测试

Eclipse-HadoopAPI开发测试#

1. 如何获取文件系统##


public static FileSystem getFileSystem() throws Exception { //读取配置文件, read core-*.xml; hdfs-*.xml Configuration configuration = new Configuration(); FileSystem fileSystem = FileSystem.get(configuration); System.out.println(fileSystem); return fileSystem; } public static void main(String[] args) throws Exception { //create configuration, read core-*.xml; hdfs-*.xml Configuration configuration = new Configuration(); FileSystem fileSystem = FileSystem.get(configuration); System.out.println(fileSystem); }

读取配置文件

public static void read(String filename)throws Exception { FileSystem fileSystem = getFileSystem(); //read Path Path readPath = new Path(filename); //input stream FSDataInputStream inStream = fileSystem.open(readPath); try{ IOUtils.copyBytes(inStream, System.out, 4096, false); }catch(Exception e){ e.printStackTrace(); } finally{ } }

写入文件

`public static void main(String[] args) throws Exception {

/* String filename = "/user/beifeng/core-site.xml";
read(filename); */
String filename = "/user/beifeng/wc.input";
FileSystem fileSystem = getFileSystem();
//read Path
Path readPath = new Path(filename); //write file
FSDataOutputStream outStream = fileSystem.create(readPath);
//get input stream
FileInputStream inStream = new FileInputStream( new File("/opt/datas/wc.input") );
try{
IOUtils.copyBytes(inStream, outStream, 4096, false);
}catch(Exception e){
e.printStackTrace();
}finally{
IOUtils.closeStream(inStream); IOUtils.closeStream(outStream);
}
}`

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,368评论 19 139
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 34,248评论 18 399
  • 1、不安全的随机数生成,在CSRF TOKEN生成、password reset token生成等,会造成toke...
    nightmare丿阅读 3,976评论 0 1
  • 摘自:http://staticor.io/post/hadoop/2016-01-23hadoop-defini...
    wangliang938阅读 677评论 0 1
  • 今天还是没有出定金,加油
    沈青青阅读 197评论 0 0

友情链接更多精彩内容