- package java2;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.Reader;
- import java.io.Writer;
- import java.util.ArrayList;
- public class Test4 {
- public static void main(String[] args){
- File source = new File("源文件");
- File purpose = new File("目的文件");
- copy(source,purpose);
- }
- public static void copy(File source,File purpose){
- ArrayList<Integer> lists = new ArrayList<Integer>();
- Reader reader = null;
- try {
- reader = new FileReader(source);
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- Writer write = null;
- try {
- write = new FileWriter(purpose);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- int num;
- try {
- while((num = reader.read())!=-1){
- lists.add(num);
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- for(Integer cha:lists){
- try {
- write.write(cha);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- write.flush();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- try {
- reader.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- write.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
复制代码 怎么运行的结果不是按照有序的排列的呢 |