• 合并多个文件到一个文件夹


    public static void main(String[] args) {
    		
    		File f1 = new File("D:/JavaTest/1.txt");
    		File f2 = new File("D:/JavaTest/2.txt");
    		File f3 = new File("D:/JavaTest/3.txt");
    		
    		String path = "D:/JavaTest/4.txt";
    		
    		joinText(path, f1, f2, f3);
    
    	}
    	
    	/**
    	 * 把所有的 file 内容合并到 path 对应的文件中
    	 * @param path
    	 * @param files
    	 */
    	public static void joinText(String path, File ...files) {
    		
    		try {
    			FileOutputStream fos = new FileOutputStream(path, true);
    			
    			for (File file : files) {
    				
    				FileInputStream fis = new FileInputStream(file);
    				
    				int length = 0;
    				
    				byte[] bytes = new byte[1024];
    				
    				while ((length = fis.read(bytes)) != -1) {
    					
    					fos.write(bytes, 0, length);
    				}
    				
    				fis.close();
    				
    				// 
     回车换行
    				fos.write("
    ".getBytes());
    			}
    			
    			fos.close();
    		} catch (FileNotFoundException e) {
    
    			e.printStackTrace();
    		} catch (IOException e) {
    
    			e.printStackTrace();
    		}
    		
    	}
    

      

  • 相关阅读:
    shiro的授权与认证
    spring-aop
    GC选择之串行收集与并行收集
    4. Tomcat调优
    spring boot 启动 开启注解 加载 bean
    一、JavaScript实现AJAX(只需四步)
    DVWA安装
    CTF入门指南
    Metasploit 学习
    JSP笔记
  • 原文地址:https://www.cnblogs.com/niuxiao12---/p/7249989.html
Copyright © 2020-2023  润新知