10 个解决方案
#1
针对你这个问题,我搜索了一下答案,我推荐你一篇博文吧,大概的意思是先获得字节流,然后用这个字节流转化为你想要的编码格式http://blog.csdn.net/zxy838279821/article/details/7536223
#2
这个你可以深入的理解一下:http://www.zhihu.com/question/20361462
#3
先读utf-8,再写ansi
#4
public static void main(String[] args) {
StringBuffer buffer=new StringBuffer();
try {
FileInputStream fis=new FileInputStream("test.txt");
InputStreamReader isr=new InputStreamReader(fis,"UTF-8");
BufferedReader br=new BufferedReader(isr);
String line=null;
while ((line=br.readLine())!=null) {
buffer.append(line);
buffer.append("\r\n");
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
FileOutputStream fos=new FileOutputStream("test1.txt");
OutputStreamWriter osw=new OutputStreamWriter(fos);
osw.write(buffer.toString());
osw.flush();
osw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
#5
不好意思,刚才没测试就发代码了
public static void main(String[] args) {
StringBuffer buffer=new StringBuffer();
try {
FileInputStream fis=new FileInputStream("test.txt");
InputStreamReader isr=new InputStreamReader(fis,"UTF-8");
BufferedReader br=new BufferedReader(isr);
String line=null;
br.skip(1);
while ((line=br.readLine())!=null) {
buffer.append(line);
buffer.append("\r\n");
}
buffer.delete(buffer.length()-2,buffer.length());
br.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(buffer);
try {
FileOutputStream fos=new FileOutputStream("test1.txt");
OutputStreamWriter osw=new OutputStreamWriter(fos);
osw.write(buffer.toString());
osw.flush();
osw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
#6
#8
要是我来做的话,把原文件读取到内存,在建一个同名的ANSI编码文件,最后写入即可
#9
如果程序在写到一半时突然被终止,数据就丢失了,必须先写入另一个文件
#10
谢谢,好人一生平安,
其实我也写出过类似的程序出来但每次“你好”前面总多出“?”出来,我以为是我的解码或编码的方法用错了,想了很久一直找不到解决方法,没想到跳过前面的?后面的就都正确了,谢谢
#1
针对你这个问题,我搜索了一下答案,我推荐你一篇博文吧,大概的意思是先获得字节流,然后用这个字节流转化为你想要的编码格式http://blog.csdn.net/zxy838279821/article/details/7536223
#2
这个你可以深入的理解一下:http://www.zhihu.com/question/20361462
#3
先读utf-8,再写ansi
#4
public static void main(String[] args) {
StringBuffer buffer=new StringBuffer();
try {
FileInputStream fis=new FileInputStream("test.txt");
InputStreamReader isr=new InputStreamReader(fis,"UTF-8");
BufferedReader br=new BufferedReader(isr);
String line=null;
while ((line=br.readLine())!=null) {
buffer.append(line);
buffer.append("\r\n");
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
FileOutputStream fos=new FileOutputStream("test1.txt");
OutputStreamWriter osw=new OutputStreamWriter(fos);
osw.write(buffer.toString());
osw.flush();
osw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
#5
不好意思,刚才没测试就发代码了
public static void main(String[] args) {
StringBuffer buffer=new StringBuffer();
try {
FileInputStream fis=new FileInputStream("test.txt");
InputStreamReader isr=new InputStreamReader(fis,"UTF-8");
BufferedReader br=new BufferedReader(isr);
String line=null;
br.skip(1);
while ((line=br.readLine())!=null) {
buffer.append(line);
buffer.append("\r\n");
}
buffer.delete(buffer.length()-2,buffer.length());
br.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(buffer);
try {
FileOutputStream fos=new FileOutputStream("test1.txt");
OutputStreamWriter osw=new OutputStreamWriter(fos);
osw.write(buffer.toString());
osw.flush();
osw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
#6
#7
#8
要是我来做的话,把原文件读取到内存,在建一个同名的ANSI编码文件,最后写入即可
#9
如果程序在写到一半时突然被终止,数据就丢失了,必须先写入另一个文件
#10
谢谢,好人一生平安,
其实我也写出过类似的程序出来但每次“你好”前面总多出“?”出来,我以为是我的解码或编码的方法用错了,想了很久一直找不到解决方法,没想到跳过前面的?后面的就都正确了,谢谢