流读取文件文件中的路径并找到路径文件进行合并

package Test_packge;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.commons.lang3.StringUtils;

public class IOinputAndOut {

	public static void main(String[] args) throws Exception {
		
		InputStream("D:/temp/txt/配置文件_1631006681442.txt","");

	}
	public static String InputStream(String pathname,String OutUTPath) throws FileNotFoundException {
		//不传路径默认路径为读取目录
		if (StringUtils.isBlank(OutUTPath)) {
			OutUTPath=pathname.substring(0,pathname.lastIndexOf("/")+1);
		}
		//根据路径截取输出文件名称
		String fileName=pathname.substring(pathname.lastIndexOf("/")+1,pathname.lastIndexOf(".")); ;
		File file=new File(pathname);
		BufferedReader reader = null;
		String tempString = null;
		int line =1;
		String fileOutPath1 = OutUTPath+fileName+".mp4";
		FileOutputStream fileOutputStream1 = new FileOutputStream(new File(fileOutPath1));
		byte[] bytes1 = new byte[1024];
		int length1 = 0;
		try {
			// System.out.println("以行为单位读取文件内容,一次读一整行:");
			reader = new BufferedReader(new InputStreamReader(new FileInputStream(file),"GBK"));
			while ((tempString = reader.readLine()) != null) {
				//System.out.println("Line"+ line + ":" +tempString);
				line ++ ;
				//文件中的路径取出来
				File file1 = new File(tempString);
				//System.err.println(tempString);
				if(!file1.exists())  
				continue;
				FileInputStream fis1 = new FileInputStream(file1);
				//取出来的字节写入指定文件
				while ((length1 = fis1.read(bytes1)) != -1) {
					fileOutputStream1.write(bytes1, 0, length1);
				}
			}
			reader.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(reader != null){
				try {
					reader.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			System.err.println("文件保存路径"+fileOutPath1);
		}
		return "已经完成";
	}
}

  

上一篇:javascript – 什么算作“网页浏览”


下一篇:Node.js 路由