码迷,mamicode.com
首页 > 其他好文 > 详细

第十周总结

时间:2019-11-03 18:20:20      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:pre   运行   构造方法   定义   mic   pack   输入流   bytes   row   

课程总结

1.File类

如果要使用File类,则要使用File类的构造方法,且实例化File类的时候,必须要给出设置好的路径。

public File (String pathname)

File类中的主要方法和常量:
技术图片
File类中的两个常量
pathSeparator:表示;
separator:表示 ###2.RandomAccessFile类
常用的操作方法:
技术图片

3.字节流与字符流基本操作:

程序需要数据的时候要使用输入流读取数据,而当程序需要将一些数据保存起来的时候,就要使用输出流完成。
技术图片
在Java中IO操作流程:
(1)使用File类打开一个文件。
(2)通过字节流或字符流的子类指定输出的位置。
(3)进行读/写操作。
(4)关闭输入/输出。

4.字节流:

字节输出流OutputStream类的定义:

public abstract class OutputStream
extends Object
implements Closeable,Flushable

OutputStream类的常用方法:
技术图片
字节输入流InputStream类的定义:

public abstract class IntputStream
extends Object
implements Closeable

InputStream类的常用方法:
技术图片

5.字符流:

字符输出流Writre类的定义:

public abstract class Writre
extends Object
implements Appendable,Closeable,Flushable

Writre类的常用方法:
技术图片

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

技术图片
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();
    }
}
技术图片

运行截图

技术图片

自我总结:

第十周总结

标签:pre   运行   构造方法   定义   mic   pack   输入流   bytes   row   

原文地址:https://www.cnblogs.com/songjiah/p/11788206.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!