从本地读入部分字节到HDFS当中
2013-12-14 17:28
155 查看
本地文件:test.txt
The modern science of networks has brought significant advances to our understanding of complex systems. One of the most relevant features of graphs representing real systems
is community structure, or clustering, i.e. the organization of vertices in clusters, with many edges joining vertices of the same cluster and comparatively few edges joining vertices of different clusters.
Java程序:
运行结果:
The modern science of networks has brought significant advances to our understanding of complex systems. One of the most relevant features of graphs representing real systems
is community structure, or clustering, i.e. the organization of vertices in clusters, with many edges joining vertices of the same cluster and comparatively few edges joining vertices of different clusters.
Java程序:
import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.InputStream; import java.io.OutputStream; import java.net.URI; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; public class FileFromLocalToHdfs { public static void main(String[] args) throws Exception { String local = args[0]; String dest =args[1]; InputStream in = new BufferedInputStream(new FileInputStream(local)); Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(URI.create(dest), conf); OutputStream out = fs.create(new Path(dest)); byte [] bytes = new byte [20]; in.skip(100); //跳过前100个字节 int readNumberOfBytes = in.read(bytes, 0, 20); //读取第101至120个字节 out.write(bytes); out.flush(); in.close(); out.close(); } }
运行结果:
相关文章推荐
- 将HDFS文件当中部分字节读入本地
- UI设计当中,任按钮的重要细节部分?
- HDFS中的部分Datanode存在大量没有删除的Block磁盘被占满
- 上传本地文件到hdfs
- Spark中加载本地(或者hdfs)文件以及SparkContext实例的textFile使用
- 命令行方式上传本地项目至Github仓库当中
- HDFS——如何将文件从HDFS复制到本地
- Hadoop实战-中高级部分 之 HDFS原理 架构和副本机制
- hadoop-hdfs-fuse本地挂载hdfs-nginx发布
- HDFS和本地文件系统的关系
- Hadoop HDFS本地存储目录结构解析
- hive查询数据导出到本地目录或hdfs的方法
- 在HTML,JSP当中使用XML与XSL展示部分数据
- 从源文件中读入2048个字节到目标文件
- hadoop创建文件夹及将本地文件移动到hdfs中
- java从hdfs中下载文件到本地
- 将本地文件拷到HDFS中
- ORA-29275:部分多字节字符
- Spark中加载本地(或者hdfs)文件以及 spark使用SparkContext实例的textFile读取多个文件夹(嵌套)下的多个数据文件
- Netty in Action (十三) 第五章节 第二部分 ByteBuf字节层面的操作