文件读取与字符串处理.
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
public class string_manipulation{
public static void deletestrs(String file_copy_from,String file_save_to) {
String teststr="";
File file1=new File(file_copy_from);
try {
FileReader filereader1=new FileReader(file1);
int ch=0;
while((ch=filereader1.read())!=-1){
teststr+=(char)ch;
}
filereader1.close();
System.out.println("ok----------------------------------------------------------------");
} catch (IOException e) {
e.printStackTrace();
System.out.println("bug----------------------------------------------------------------");
}
String str2=teststr.replaceAll("", "");
System.out.println(teststr+"\n----------------------------------------------------------------"+str2);
FileOutputStream outputstream1=null;
try {
File file2=new File(file_save_to);
outputstream1=new FileOutputStream(file2);
outputstream1.write(str2.getBytes());
} catch (Exception e) {
e.printStackTrace();
System.out.println("bug-output----------------------------------------------------------------");
} finally{
try {
outputstream1.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
string_manipulation.deletestrs("E:\\a.txt", "E:\\b.txt");
}
}