- package newTest;
-
-
- import java.io.*;
-
- public class test2 {
- //目标: 掌握字符输入转换流
- public static void main(String[] args) {
- try(
- //文件管道对象
- //得到原始的字节编码
- InputStream fs=new FileInputStream( "src/zFIle/zhuanhuan.txt");
- //读取指定的字节编码格式
- Reader is= new InputStreamReader(fs,"GBK");
- //缓冲池
- BufferedReader br= new BufferedReader(is);
-
- ) {
- String c;
- while ((c=br.readLine())!=null){
- System.out.println(c);
- }
- //创建读取文件按
- } catch (Exception e) {
- e.printStackTrace();
- }
-
-
- }
- }
- package newTest;
-
-
- import java.io.*;
-
- public class Transition {
- //目标:字符输出转换流
- public static void main(String[] args) {
-
- try (
- ///指定的编码写入出去
- //1:创建一个文件
-
- OutputStream os= new FileOutputStream("src/zFIle/zhuanhuan001.txt");
- //2:字符转换
- Writer osw=new OutputStreamWriter(os,"UTF-8" );
- //缓冲池
- BufferedWriter bfw=new BufferedWriter(osw);
-
- ){
-
- bfw.write("我爱中国abc");
- bfw.write("我爱中国1234");
-
-
-
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
- }