美文网首页
常用文件处理方法

常用文件处理方法

作者: 大闪电啊 | 来源:发表于2019-09-30 09:55 被阅读0次

GBK格式内容转码

    val logRdd = sc.hadoopFile(logPath, classOf[TextInputFormat], classOf[LongWritable], classOf[Text])
      .map(p => new String(p._2.getBytes, 0, p._2.getLength, "GBK"))

获取文件路径或文件名

hadoop mr 中使用如下方式
InputSplit inputSplit=(InputSplit)context.getInputSplit();  
String filename=((FileSplit)inputSplit).getPath().getName();  
spark 中

获取文件名中的ip信息,并将文件转码

    val logRdd = sc.hadoopFile(logPath, classOf[TextInputFormat], classOf[LongWritable], classOf[Text])
      .asInstanceOf[HadoopRDD[LongWritable,Text]]
      .mapPartitionsWithInputSplit((inputSplit:InputSplit, iterator:Iterator[(LongWritable, Text)]) => {
        val file = inputSplit.asInstanceOf[FileSplit]
        val fileName = file.getPath.getName()
        val reg = "((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})(\\.((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})){3}".r
        val ip = reg.findFirstIn(fileName)
        iterator.map(x => {ip.getOrElse("") + SEPRATOR + new String(x._2.getBytes, 0, x._2.getLength, "GBK")})
      })

相关文章

  • 常用文件处理方法

    GBK格式内容转码 获取文件路径或文件名 hadoop mr 中使用如下方式 spark 中 获取文件名中的ip信...

  • Python3 OS 文件/目录方法

    os 模块提供了非常丰富的方法用来处理文件和目录。常用的方法如下表所示:

  • 文件下载

    angluar中文件下载常用的处理方法接口是Get情况 const url = "https://www.jian...

  • Python3入门(十一)OS文件/目录方法

    os模块提供了非常丰富的方法用来处理文件和目录。常用的方法如下表所示 本文到此结束

  • Python: os模块

    os 模块提供了非常丰富的方法用来处理文件和目录。 常用的方法如下表所示:https://www.runoob.c...

  • iOS NSFileManager

    简介 由于项目需要,整理了一份文件处理的方法。 下面是一些常用的方法: 获取Document路径 获取Librar...

  • I/O

    获取文件信息 File类的常用方法 压缩文件 ZipOutputStream类的常用方法 解压缩ZIP文件 ZIP...

  • SpringMVC配置和常用Controller方法

    常用的映射处理器配置与常用Controller的方法 Controoler方法

  • python内置os模块

    os模块 python的os 模块提供了非常丰富的方法用来处理文件和目录。 os常用系统操作

  • WTForms 字段 参数 校验

    常用字段 常用参数 常用校验 文件上传 表单提交属性 表单处理流程

网友评论

      本文标题:常用文件处理方法

      本文链接:https://www.haomeiwen.com/subject/dpwyhctx.html