IO概述

1、IO流用来处理设备之间的数据传输

2、Java对数据的操作是通过流的方式

3、Java用于操作流的对象都在IO包中

流按操作数据分为两种:字节流字符流,字符流是基于字节流

字节:字节英语Byte。一个字节代表八个比特。它通常用作计算机信息计量单位,不分数据类型。它也是程序设计语言里不可缺少的基本数据类型。在处理图片、音视频文件时就只能使用字节流。

字符:电脑电信领域中,字符Character)是一个信息单位,一个字符是一个单位的字形、类字形单位或符号的基本信息

字符是指计算机中使用的字母、数字符号

电脑和通信设备会在表示字符时,会使用字符编码。是指将一个字符对应为某个东西。传统上,是代表整数比特序列,如此,则可通过网络传输,同时亦便于存储。两个常用的例子是ASCII和用于Unicode编码UTF-8。根据Google的统计,UTF-8是目前最常用于网页的编码方式。相较于大部分的字符编码把字符对应到数字或比特串

IO流常用基类:

字节流的抽象基类:InputStream ,OutputStream

字符流的抽象基类:Reader ,Writer

由这四个类派生出来的子类名称都是以其父类名作为子类名的后缀

如:InputStream的子类FileInputStream。
如:Reader的子类FileReader。


编程:

FileWriter(String fileName)
Constructs a FileWriter object given a file name. the 0riginal file will be override if once gain run.
public static void main(String[] args) {
FileWriter file = null;
try {
file = new FileWriter("F:\\fileIo.txt"); //Constructs a FileWriter object given a file name.
file.write("use FileWriter write string.");  //Writes a string.
} catch (IOException e) {
e.printStackTrace();
}finally{
if(file != null){
try {
file.close(); //Closes the stream, flushing it first.
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Constructors:
FileWriter(String fileName, boolean append)
Constructs a FileWriter object given a file name with a boolean indicating whether or not to append(
  • append - boolean if true, then data will be written to the end of the file rather than the beginning.
) the data written.
public static void main(String[] args) {
FileWriter file = null;
try {
file = new FileWriter("F:\\file02.txt", true);
file.write("File Continue to write..");
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
void write(String str)
Writes a string.


void flush()
Flushes the stream.
void close()
Closes the stream, flushing it first.
void write(int c)
Writes a single character.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值