Java笔记整理 —— 其它流和Properties

标准输入输出流

public final static InputStream in = null;

public final static PrintStream out = null;

System.in 编译类型:InputStream,运行类型:BufferedInputStream。表示的是标准输入 键盘

System.out 编译类型:PrintStream,运行类型:PrintStream。 表示的是标准输入 显示器

转换流 

默认情况下,读取文件是按照UTF-8编码,如果文件按照别的方式编码,就很容易读取到乱码。

 

包装:其实就是转换。 

String filePath = "d:\\a.txt";
InputStreamReader isr = new InputStreamReader(new FileInputStream(filePath,"gbk"));
//注意文件编码格式是啥,就转化成啥格式
BufferedReader br = new BufferedReader(isr); //包装转换流,转换成字符流

String s = br.readLine();
br.close(); //关闭外层流

打印流

只有输出流,没有输入流。

        PrintStream out = new PrintStream(System.out);
        out.println("hello");
        out.write("你好,世界".getBytes());
        //print底层调用的是write,所以可以直接调用write进行打印
        out.close(); //注意由于out是System.out,这个一结束,sout就不能用了
        System.out.println("wowowo"); //无法输出
        PrintStream out2 = new PrintStream("d:\\a.txt");
        System.setOut(out2);
        //修改打印流输出的位置
        System.out.println("1111"); //输出到文件当中
    public static void main(String[] args) throws IOException {
        FileWriter fileWriter = new FileWriter("d:\\a.txt");
        PrintWriter printWriter = new PrintWriter(fileWriter);
        printWriter.print("hello,world!!!!!!");
        printWriter.flush();
        //printWriter.close(); //flush或者close调用一个,才能输入进去
    }

Properties  

注:键值对不需要有空格,值不需要用引号引起来,值的默认类型是String。

     store方法的第二个参数是注释,null表示没有注释。在store方法中,如果没有这个文件就是创建,如果有这个文件就是修改。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值