FileRW
package
filereader;
import
java.io.FileNotFoundException;
import
java.io.FileReader;
import
java.io.FileWriter;
import
java.io.IOException;
import
java.io.Reader;
import
java.io.Writer;
public
class FileRW {
public void fileReaderWriter(String sourcePath, String destinationPath) throws IOException {
Reader fr = new FileReader(sourcePath);
char[] buffer = new char[1024];
StringBuffer sb = new StringBuffer();
int length = fr.read(buffer);
while (length != -1) {
sb.append(buffer);
length = fr.read(buffer);
}
// System.out.println(sb);
fr.close();
Writer fw = new FileWriter(destinationPath);
fw.write(buffer);
if (null != fw) {
fw.close();
}
}
}
package
filereader;
import
java.io.IOException;
public
class FileRWTest {
public static void main(String[] args) {
FileRW frw=new FileRW();
String sourcePath="Q:/Users/a496006.DMN1.000/Desktop/s.txt";
String destinationPath="Q:/Users/a496006.DMN1.000/Desktop/d.txt";
try {
frw.fileReaderWriter(sourcePath, destinationPath);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}