不多说,直接上干货!

 

  有时候,我们需要用到这样的一个场景。

 java编程如何实现从本地里读取文件1,写入到本地另一个文件2里(多种场景)

 

 

 

ReadLocalFile1WriteLocalFile2.java

(以下是相当于复制,读取文件1里的全部内容,并写入到文件2里)

package zhouls.bigdata.DataFeatureSelection.util;

import java.io.FileInputStream;  
import java.io.FileOutputStream;  
import java.io.IOException;  
import java.io.InputStream;  
import java.io.OutputStream;  
import java.net.MalformedURLException;  


public class ReadLocalFile1WriteLocalFile2 { 
     /** 
     * 从本地文件1.txt读取数据写入本地文件2.txt 
     * 
     * @author zhouls 
     * 
     */  
    public static void main(String[] args) throws IOException {   
        //输入流  
        InputStream in = new FileInputStream("F:/datamode/SnortFeatureSelectionData.txt");  
        //输出流  
        OutputStream out = new FileOutputStream("F:/datamode/SnortFeatureSelectionData2.txt", true);  
  
        try {  
            byte[] buffer = new byte[1024];  
            while (true) {  
                int byteRead = in.read(buffer);  
                if (byteRead == -1)  
                    break;  
                out.write(buffer, 0, byteRead);  
            }  
        }  
  
        catch (MalformedURLException ex) {  
            System.err.println(args[0] + " is not a URL Java understands.");  
        } finally {  
            if (in != null)  
                in.close();  
            if (out != null) {  
                out.close();  
            }  
        }  
    }  

}

 

 

 

 

  得到

java编程如何实现从本地里读取文件1,写入到本地另一个文件2里(多种场景)

 

相关文章:

  • 2022-12-23
  • 2021-05-30
  • 2021-11-29
  • 2021-11-12
  • 2022-12-23
  • 2021-10-17
  • 2021-10-24
猜你喜欢
  • 2022-03-04
  • 2022-12-23
  • 2022-01-07
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
相关资源
相似解决方案