有时测试需要单独生成1个文件后拿出来看看内容,spark自动生成的块文件名不好说明文件用途
源文件
修改后
package myspark.core
import java.io.File
import scala.reflect.io.Directory
object getFile{
def main(args: Array[String]): Unit = {
val testPath="C:\\output\\testJSON"
renameFiles(testPath,"testRename","json")
}
/**
* 修改某个路径下的所有文件名为:newName_index.fileType
* @param path 文件所在路径
* @param newName 新的文件名
* @param fileType 文件类型
*/
def renameFiles(path:String,newName:String,fileType:String)={
val dirPath=new Directory(new File(path))
val files=dirPath.files.toList.filter(x=>"""crc$|_SUCCESS$""".r.findFirstIn(x.path).isEmpty)
files.indices.foreach(x=>{new File(files.apply(x).path).renameTo(new File(files.apply(x).parent.path+File.separator+s"${newName}_${x.toString}.${fileType}"))})
}
}