展开全部
辛苦写的,不会有乱码,测试下,行就采纳吧!
package test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Test1 {
public static void main(String[] args) throws IOException {
String txtFilePath = "d:/aaaaa.txt";//原文件
FileInputStream fis = new FileInputStream(new File(txtFilePath));
InputStreamReader isr = new InputStreamReader(fis,"GBK");
BufferedReader reader = new BufferedReader(isr);
String otherTxtFilePath = "d:/test_lower.txt";//保存小写的文件
FileOutputStream fos = new FileOutputStream(new File(otherTxtFilePath));
OutputStreamWriter osw = new OutputStreamWriter(fos,"GBK");
BufferedWriter writer = new BufferedWriter(osw);
String line = null;
while((line = reader.readLine()) != null){
writer.append(line.toLowerCase()).append("\r\n");
}
writer.close();
reader.close();
}
}
package test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Test1 {
public static void main(String[] args) throws IOException {
String txtFilePath = "d:/aaaaa.txt";//原文件
FileInputStream fis = new FileInputStream(new File(txtFilePath));
InputStreamReader isr = new InputStreamReader(fis,"GBK");
BufferedReader reader = new BufferedReader(isr);
String otherTxtFilePath = "d:/test_lower.txt";//保存小写的文件
FileOutputStream fos = new FileOutputStream(new File(otherTxtFilePath));
OutputStreamWriter osw = new OutputStreamWriter(fos,"GBK");
BufferedWriter writer = new BufferedWriter(osw);
String line = null;
while((line = reader.readLine()) != null){
writer.append(line.toLowerCase()).append("\r\n");
}
writer.close();
reader.close();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询