第十周课程总结

将奇数位的字母变成大写#

源代码#

package java7;
import java.io.*;
public class Demo {

    public static void main(String[] args) throws Exception{                         //异常抛出,不处理
        File f1=new File("d:"+File.separator+File.separator+"demo.txt");             //声明File对象
        OutputStream out=null;                       //准备好一个输出对象
        out=new FileOutputStream(f1);           //通过对象多态性,进行实例化
        String str="i love lyf";                           //准备一个字符串
        byte b[]=str.getBytes();                       //只能输出byte数组,所以将字符串变成byte数组
    	for (int i = 0; i < b.length; i++) {
			out.write(b[i]); 		// 将内容输出
	}
    	out.close(); 
    	File f2=new File("d:"+File.separator+File.separator+"demo.txt");             //声明File对象
    	InputStream input=null; //准备好一个输入的对象 
        input=new FileInputStream(f2); //通过对象的多态性,进行实例化 
        byte c[]=new byte[(int)f2.length()]; //所有的内容读到此数组之中
        input.read(c);
        for(int i=0;i<c.length;i++) {
            if(i%2==0) {             //判断是否是奇数
                c[i]=(byte) (c[i]+'A'-'a');
            }
        }
        input.close();
        System.out.println(new String(c));
    }
}

实验结果#

学习总结#

1.File类中的主要方法和常量

2.RandomAccessFile类的常用操作方法

3.
字节流主要是操作byte类型数据,以byte数组为准,主要操作类就是OutputStream、InputStream。 
字节输出流:OutputStream 
字节输入流:InputStream 

4.OutputStream类的常用方法

5.InputStream类的常用方法

6.Writer类的常用方法

7.Reader类的常用方法

学习总结:本周无实验报告,希望下周的实验报告不要太难啊!这周讲的东西有点多也很重要,要好好消化#

原文地址:https://www.cnblogs.com/lxzlyf2022/p/11770522.html