java笔记(五)

标准输入/输出类System

标准输入流

out
Systm.out.println();


标准错误流
err
System.out.println();


标准输出流
in对象的类型是InputStream,提供了两个方法
read()方法读取一个字节
read(byte[] b)读取一个字节数组


文件操作类File
File(String pathname):通过将给定路径名字字符串转换为抽象路径来创建一个新的File实例
例:
File path = new File("D:/demo");        //目录对象
File path = new File("D:/demo/text.txt");    //文件对象


File(String parent,String child):根据parent路径名字符串和child路径名字符串创建一个新的File实例
例:
File file = new File("D:/demo","text.txt");    //文件对象

File(URL url):通过将给定的file:URL转换为一个抽象路径名来创建一个新的File实例

例:

File file = new File("file://D:/demo/text.txt");

File(File parent,String child):根据parent抽象路径名和child路径名字符串创建一个新的File实例

例:

File file = new File(path,"text.txt");


判断是目录还是文件
isdirectory() : 是否是目录
isFile() : 是否是文件

检查目录或文件是否存在

exists()


文件搜索类FileFilter与FilenameFilter
boolean accept(File file);

boolean accept(File directory,String name);
按照目录和文件名来进行过滤

关闭
close()

读取文件长度
length()

读取文件           写入文件与读入类似(write)

1:读取一个数据字节
read()

2:读取字节数组
read(byte[] b)

3:灵活读取字节数组
read(byte[] b,int off,int len)
例:
read(b,0,length)

4:读取固定类型的数值
boolean readBoolean()
byte readByte()
char readChar()
double readdouble()
float readFloat()
int readInt()

5:读取一行字符串
readLine()

6:读取中文字符
readUTF()

IO流

输入字节流
抽象类                   InputStream
文件类                   FileInputStream
过滤类                   FilterInputStream
缓存类                   BufferedInputStream

输出字节流
抽象类                   OutputStream
文件类                   FileOutputStream
过滤类                   FilterOutputStream
缓存类                   BufferedOutputStream
格式化                  PrintStream

输入字符流
抽象类                  Reader
转换类                  InputStreamReader
文件类                   FileReader
过滤类                   FilterReader
缓存类                   BufferedReader

输出字节符
抽象类                  Writer
转换类                  OutputStreanWriter
文件类                   FileWriter
过滤类                   FilterWriter
格式化                  PrintWriter



常用:

输出流:PrintWriter

输入流:Scanner



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值