1 7 package com.inversoft.util; 8 9 10 import java.io.BufferedReader ; 11 import java.io.BufferedWriter ; 12 import java.io.File ; 13 import java.io.FileReader ; 14 import java.io.FileWriter ; 15 import java.io.IOException ; 16 17 18 26 public class FileTools { 27 28 36 public static String convertPath(String path) { 37 38 String newPath; 39 if (File.separatorChar == '\\') { 40 newPath = path.replace('/', '\\'); 41 } else { 42 newPath = path.replace('\\', '/'); 43 } 44 45 return newPath; 46 } 47 48 57 public static void copy(File from, File to) throws IOException { 58 59 if (to.exists()) { 61 to.delete(); 62 } 63 64 FileReader reader = new FileReader (from); 65 BufferedReader br = new BufferedReader (reader); 66 FileWriter writer = new FileWriter (to); 67 BufferedWriter bw = new BufferedWriter (writer); 68 69 char [] buf = new char[1024]; 70 int count = 0; 71 do { 72 count = br.read(buf, 0, 1024); 73 if (count != -1) { 74 bw.write(buf, 0, count); 75 } 76 } while (count != -1 && count == 1024); 77 78 bw.close(); 79 br.close(); 80 writer.close(); 81 reader.close(); 82 } 83 } | Popular Tags |