第十周课程总结

作业

把奇数位 的小写字母改为大写

package 字符流;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

public class Test{
    public static void main(String[]args)throws Exception{
        File f=new File("f:"+File.separator+"test.txt");
        OutputStream out=null;
        out =new FileOutputStream(f);
        String str="helloworld";
        byte a[]=str.getBytes();
        for(int i=0;i<a.length;i++) {
            if(i%2==0&&a[i]>='a'&&a[i]<='z') {
                a[i]=(byte)(a[i]-32);
            }
        }
        out.write(a);
        out.close();
    }
}

运行截图

 学习总结

1、字节输出流:OutputSream

定义

 OutputStream类的常用方法

 字节输入流:InputStream

定义及其常用方法:

 2、字符输出流Writer

定义及其常用方法

 字符输入流Reader

定义及其常用方法

 3、字节流和字符流的区别

原文地址:https://www.cnblogs.com/JokerXue/p/11784264.html