Java 瀛楃鐮併€佸瓧绗︽祦銆佸瓧鑺傛祦
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java 瀛楃鐮併€佸瓧绗︽祦銆佸瓧鑺傛祦相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e5%ad%97%e7%ac%a6%e6%95%b0%e7%bb%84' title='瀛楃鏁扮粍'>瀛楃鏁扮粍
har 鏂囦欢 buffer font file 鍥剧墖瀛楃缂栫爜琛?/p>
Ascii: 0-xxxxxxx姝f暟
iso-8859-1: 鎷変竵鐮佽〃1-xxxxxxx 璐熸暟銆?/span>
GB2312: 绠€浣撲腑鏂囩爜琛?/p>
GBK: 鏈€甯哥敤鐨勪腑鏂囩爜琛?String瀛楃涓查粯璁?/span>
GB18030锛?/span> 鏈€鏂扮殑涓枃鐮佽〃
unicode锛?/span> 鍥介檯鏍囧噯鐮佽〃 char瀛楃榛樿 姣忎釜瀛楃涓ゅ瓧鑺?/span>
UTF-8: 鍩轰簬unicode 姣忎釜瀛楃涓€涓垨涓や釜瀛楄妭
鑳借瘑鍒腑鏂囩殑鐮佽〃锛?/span>GBK銆?/span>UTF-8
甯歌鐨勭紪鐮?/span> GBK UTF-8 ISO-8859-1
鏂囧瓧--->(鏁板瓧) 锛氱紪鐮?鈥?/span>abc鈥?/span>.getBytes() byte[]
(鏁板瓧)--->鏂囧瓧 : 瑙g爜 byte[] b={97,98,99} new String(b,0,len)
ANSI:绯荤粺缂栫爜
銆€銆€銆€銆€銆€銆€瀛楄妭娴?In 銆€銆€銆€銆€銆€銆€銆€ 瀛楃娴?/span> 瑕佸埛鏂癛eader
鎶借薄绫汇€€銆€ OutputStream 銆€銆€銆€銆€銆€銆€ 銆€銆€Writer
銆€銆€銆€銆€銆€銆€銆€銆€|銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€ / 銆€ 銆€銆€
瀹炵幇绫汇€€銆€ FileOutputStream銆€銆€ +銆€銆€ OutputStreamWriter = FileWriter
銆€銆€銆€銆€銆€銆€銆€銆€|銆€銆€銆€銆€銆€銆€ 銆€銆€銆€銆€ 缂栫爜銆€銆€銆€銆€銆€銆€銆€銆€ |
缂撳啿娴併€€銆€ BufferedOutputStream PrintStream銆€銆€ 銆€銆€銆€銆€銆€BufferedWriter
瀛楄妭娴侊紙鍥剧墖锛?/p>
FileOutputStream FileInputStream
public static void method01() throws IOException{
//FileOutputStream fos=new FileOutputStream(file);//浼犲叆File瀵硅薄
//FileOutputStream fos=new FileOutputStream("F:\a.txt");//鍒涘缓/瑕嗙洊
FileOutputStream fos=new FileOutputStream("F:\java\a.txt",true);/杩藉姞
fos.write(97); //鍐欏叆瀛楄妭 姝f暟锛?/span>Ascll鐮?a 璐熸暟锛氬崐涓眽瀛?/span> 鎴?/span>?
byte[] bytes={97,98,99,100};
fos.write(bytes); // 鍐欏叆涓€涓? 瀛楄妭 鏁扮粍
fos.write(bytes,1,1); // 浠?/span>1寮€濮? 闀垮害涓?/span>1
String str="浣犲ソ锛屼腑鍥?/span>2 "; // 鎹㈣锛?/span>
fos.write(str.getBytes()); // 瀛楃涓?杞?瀛楄妭鏁扮粍 鍐欏叆
fos.close();
}
瀛楃娴侊紙鏂囨湰锛屽彧鑳芥槸gbk鏍煎紡锛?/span>
public static void main(String[] args) throws IOException {
//FileWriter fw = new FileWriter("d:\a.txt");//鍒涘缓杈撳嚭娴佸璞?/span>
//FileWriter fw = new FileWriter("b.txt");//椤圭洰璺緞涓?鍒涘缓鏂囦欢
FileWriter fw = new FileWriter("c.txt",true); //杩藉姞鍐欏叆=true
fw.write("helloworld");//鍐欏叆瀛楃涓?/span>
fw.write(" ");//windows: linux: mac:
//fw.flush();//瀛楃闇€瑕?鍒锋柊缂撳啿鍖?/span>
fw.write("abcde",0,5);//鍐欏叆瀛楃涓?璧峰绱㈠紩 闀垮害
fw.write(鈥榓鈥?;//鍐欏叆瀛楃char a
fw.write(97);//鍐欏叆瀛楃 瀵瑰簲鐨?/span>Ascll鐮? a
char[] chs = {鈥榓鈥?鈥榖鈥?鈥榗鈥?鈥榙鈥?鈥榚鈥榼;
fw.write(chs); //abcde
fw.write(chs,2,3);//鍐欏叆瀛楃鏁扮粍 璧峰绱㈠紩 闀垮害
fw.close();//鍒锋柊缂撳啿鍖?/span>+閲婃斁璧勬簮
}
以上是关于Java 瀛楃鐮併€佸瓧绗︽祦銆佸瓧鑺傛祦的主要内容,如果未能解决你的问题,请参考以下文章