`
Josh_Persistence
  • 浏览: 1633453 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类

Java 复制文件内容

阅读更多

package com.wsheng.cms.cms.test;

 

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.OutputStreamWriter;

 

import org.junit.Test;

 

public class FileSyncTest  {

    

    // change to the real file path

    private final static String PRO_FILE = "C:/cloudvipzonefile.txt";

    

    private final static String LOCAL_FILE = "\\src\\test\\resources\\dnsfiles\\testzonefile.txt";

 

    @Test

    public void copyContents() {

        try {

            String projectPath = System.getProperty("user.dir");

 

            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(PRO_FILE)));

            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(projectPath + LOCAL_FILE)));

            

            String currentLineData = null;

            while ((currentLineData = br.readLine()) != null) {

                bw.write(currentLineData);

                bw.newLine(); // line feed,需要换行

            }

            bw.close();

            br.close();

        } catch (FileNotFoundException e) {

            e.printStackTrace();

        } catch (IOException ioe) {

            ioe.printStackTrace();

        }

        

    }

}

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics