获取hdfs文件下所有文件getAllFiles 遍历 spark读取


1 package com.spark.demo

 import java.io.IOException
import java.net.URI import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs._ object HdfsUtil { val conf: Configuration = new Configuration()
var fs: FileSystem = null
var files: RemoteIterator[LocatedFileStatus] = null def getFiles(HDFSPath: String) = {
try {
fs = FileSystem.get( new URI( HDFSPath ), conf )
} catch {
case e: IOException => {
e.printStackTrace
}
}
files
} def getFiles(HDFSPath: String, targetPath: String) = {
try {
fs = FileSystem.get( new URI( HDFSPath ), conf )
// 返回指定路径下所有的文件
files = fs.listFiles( new Path( targetPath ), false )
} catch {
case e: IOException => {
e.printStackTrace
}
}
files
} def mkdir(finalPath: String) = {
fs.create( new Path( finalPath ) )
} def rename(oldPath: String, finalPath: String) = {
fs.rename( new Path( oldPath ), new Path( finalPath ) )
} def exist(existPath: String): Boolean = {
fs.exists( new Path( existPath ) )
} def delete(deletePath: String) = {
fs.delete( new Path( deletePath ), true )
} def read(readPath: String) = {
fs.open( new Path( readPath ) )
}
def getAllFiles(path:String): Array[FileStatus] ={
val fs = FileSystem.get(URI.create(path), conf)
val files= fs.listStatus(new Path(path))
for(file<-files){
println( file.getPath.getName)
println(file.getPath.toString)
}
files } def main(args: Array[String]): Unit = {
getAllFiles("hdfs://10.10.4.1:8020/ibc/datalogs/apachelogs/archive/2018")
} def close() = {
try {
if (fs != null) {
fs.close()
}
} catch {
case e: IOException => {
e.printStackTrace
}
}
} }

scala 操作hdfs的更多相关文章

  1. geotrellis使用(五)使用scala操作Accumulo

    要想搞明白Geotrellis的数据处理情况,首先要弄清楚数据的存放,Geotrellis将数据存放在Accumulo中. Accumulo是一个分布式的Key Value型NOSQL数据库,官网为( ...

  2. java操作hdfs实例

    环境:window7+eclipse+vmware虚拟机+搭建好的hadoop环境(master.slave01.slave02) 内容:主要是在windows环境下,利用eclipse如何来操作hd ...

  3. Hadoop操作hdfs的命令【转载】

    本文系转载,原文地址被黑了,故无法贴出原始链接. Hadoop操作HDFS命令如下所示: hadoop fs 查看Hadoop HDFS支持的所有命令 hadoop fs –ls 列出目录及文件信息 ...

  4. 使用javaAPI操作hdfs

    欢迎到https://github.com/huabingood/everyDayLanguagePractise查看源码. 一.构建环境 在hadoop的安装包中的share目录中有hadoop所有 ...

  5. Scala操作Hbase空指针异常java.lang.NullPointerException处理

    Hbase版本:Hortonworks Hbase 1.1.2 问题描述:使用Scala操作Hbase时,发生空指针异常(java.lang.RuntimeException: java.lang.N ...

  6. 关于操作HDFS的一个问题

    近日写程序定时任务调Hadoop MR程序,然后生成报表,发送邮件,当时起了两个任务A和B,调MR程序之前,会操作hdfs(读写都有),任务A每天一点跑,任务B每十分钟跑一次,B任务不会调用MR程序, ...

  7. 使用Java API操作HDFS文件系统

    使用Junit封装HFDS import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.*; import org ...

  8. 使用Eclipse来操作HDFS的文件

    一.常用类 1.Configuration Hadoop配置文件的管理类,该类的对象封装了客户端或者服务器的配置(配置集群时,所有的xml文件根节点都是configuration) 创建一个Confi ...

  9. Hadoop Java API操作HDFS文件系统(Mac)

    1.下载Hadoop的压缩包 tar.gz   https://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/stable/ 2.关联jar包 在 ...

随机推荐

  1. 火币网API文档——Websocket 请求与订阅示例

    1. 访问地址 Pro 站行情请求地址为:wss://api.huobipro.com/ws HADAX 站行情请求地址为:wss://api.hadax.com/ws 2. 数据压缩 WebSock ...

  2. 唯美MACD

    上证30 分钟产生背离,60 分钟高位,但并没有背离,若调整,也是30F 级别的.算是上涨途中的歇脚. 1.股票如果非要从MACD 上去判断怎么拿,那么一句话:要大跌,一般都需要背离.所以,没有背离的 ...

  3. 帝国cms-tab

    <ul class="intro_commenTab"> [e:loop={"select classname,classpath,classid from ...

  4. ES6封装原生ajax请求

    http (data) { return new Promise((resolve, reject) => { var xhr = new XMLHttpRequest(); xhr.onrea ...

  5. 什么是AOP面向切面编程

    什么是AOP 连接地址:http://blog.csdn.net/moreevan/article/details/11977115/ AOP(Aspect-OrientedProgramming,面 ...

  6. 背景图宽高100%无法无法显示的问题【body设置relative,当前元素absolute】

    以下1,2两个关键元素 body{   width:100%;   height:100%;   position:relative; //1 } .login-form { width: 100%; ...

  7. [LeetCode] 364. Nested List Weight Sum II_Medium tag:DFS

    Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...

  8. asp.net拦截器

    一 拦截器又称过滤器. asp.net mvc本身是自带3种拦截器:Action拦截器.Result拦截器.Exception拦截器. 应用中常见的拦截器有日志拦截器(Action拦截器)和异常处理拦 ...

  9. 第零章 HTML启蒙知识与网站开发流程

    Web前端启蒙知识:1.软件架构模式a)B/S架构:Browser-Server 浏览器服务器模型b)C/S架构:Client-Server 客户端服务器模型注1:浏览器是运行网页的应用程序注2:B/ ...

  10. Unity shader学习之Forward Rendering Path

    Forward rendering path shader如下: // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObje ...