标签:[] 流转 ade 字符 import 流操作 pac 子类 put
String(byte[] bytes, Charset charset)
public byte[] getBytes(Charset charset)
package com.xuweiwei; import java.io.UnsupportedEncodingException; public class StringDemo { public static void main(String[] args) throws UnsupportedEncodingException { String str = "abcdef"; //编码 byte[] bytes = str.getBytes("UTF-8"); for (byte aByte : bytes) { System.out.println("aByte = " + aByte +"、" ); } //解码 System.out.println("解码:"+new String(bytes,"UTF-8")); } }
public OutputStreamWriter(OutputStream out, String charsetName) throws UnsupportedEncodingException
package com.xuweiwei; import java.io.*; public class OutputStreamWriterDemo { public static void main(String[] args) throws IOException { Writer ow = new OutputStreamWriter(new FileOutputStream("ow.txt"),"utf-8"); ow.write("你好,许威威"); ow.close(); } }
public InputStreamReader(InputStream in, String charsetName) throws UnsupportedEncodingException
package com.xuweiwei; import java.io.*; public class InputStreamReaderDemo { public static void main(String[] args) throws IOException { Reader reader = new InputStreamReader(new FileInputStream("ow.txt"),"utf-8"); char[] buffer = new char[1024]; int len = 0; while(-1 != (len = reader.read(buffer))){ System.out.println(new String(buffer,0,len)); } reader.close(); } }
package com.xuweiwei; import java.io.FileWriter; import java.io.IOException; public class FileWriterDemo { public static void main(String[] args) throws IOException { FileWriter fw = new FileWriter("fw.txt"); fw.write("你好啊"); fw.close(); } }
public void newLine() throws IOException
public String readLine()
package com.xuweiwei; import java.io.*; public class BufferedWriterDemo { public static void main(String[] args) throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter("bw.txt")); bw.write("你好啊"); bw.flush(); bw.close(); } }
package com.xuweiwei; import java.io.FileWriter; import java.io.IOException; public class FileWriterDemo { public static void main(String[] args) throws IOException { FileWriter fw = new FileWriter("fw.txt"); fw.write("你好啊"); fw.close(); } }
package com.xuweiwei; import java.io.*; public class CopyDemo { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new FileReader("br.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("bw.txt")); String line = null; while(null != (line = br.readLine())){ bw.write(line); bw.newLine(); bw.flush(); } bw.close(); br.close(); } }
标签:[] 流转 ade 字符 import 流操作 pac 子类 put
原文地址:https://www.cnblogs.com/xuweiweiwoaini/p/9386439.html