import java.io.IOException
public class CovertEncode {
public static void main(String args[]) throws Exception {
CovertFile("d:\\1.txt")
}
public static void CovertFile(String filename) throws IOException {
String backupfilename = filename + ".backup"
File f = new File(filename)
File outf = new File(backupfilename)
f.renameTo(outf)
java.io.FileInputStream in = new java.io.FileInputStream(backupfilename)
java.io.InputStreamReader isr = new java.io.InputStreamReader(in, "Big5")
java.io.BufferedReader br = (new java.io.BufferedReader(isr))
// open output stream
java.io.FileOutputStream out = new java.io.FileOutputStream(filename)
java.io.BufferedWriter bw = new java.io.BufferedWriter(
new java.io.OutputStreamWriter(out, "GBK"))
char[] buffer = new char[4096]
int len
while ((len = br.read(buffer)) != -1)
bw.write(buffer, 0, len)
br.close()
bw.flush()
bw.close()
outf.deleteOnExit()
}
}
过去的所谓"unicode编码"其实是指ucs-16编码,unicode是指字符集,连gb18030都是unicode编码。而“unicodebig
endian
”是如笑utf-16be编码,也属于unicode编码.
可以改成
outputstreamwriter
out
=
new
outputstreamwriter(new
fileoutputstream(file,true),"utf-16le")//应该就是你要的不稿橡滑严谨的"键腊unicode"编码
import java.io.Fileimport java.io.IOExceptionpublic class CovertEncode { public static void main(String args[]) throws Exception { CovertFile("码好渗d:\袜氏\迟脊1.txt")} public static void CovertFile(String filename) throws IOException欢迎分享,转载请注明来源:内存溢出
评论列表(0条)