IO概述
来源:互联网 发布:mac推出磁盘快捷键 编辑:程序博客网 时间:2024/06/15 16:05
1、IO流用来处理设备之间的数据传输
2、Java对数据的操作是通过流的方式
3、Java用于操作流的对象都在IO包中
2、Java对数据的操作是通过流的方式
3、Java用于操作流的对象都在IO包中
流按操作数据分为两种:字节流与字符流,字符流是基于字节流
字节:字节,英语:Byte。一个字节代表八个比特。它通常用作计算机信息计量单位,不分数据类型。它也是程序设计语言里不可缺少的基本数据类型。在处理图片、音视频文件时就只能使用字节流。
字符:在电脑和电信领域中,字符(Character)是一个信息单位,一个字符是一个单位的字形、类字形单位或符号的基本信息。
字符是指计算机中使用的字母、数字、字和符号。
电脑和通信设备会在表示字符时,会使用字符编码。是指将一个字符对应为某个东西。传统上,是代表整数的比特序列,如此,则可通过网络来传输,同时亦便于存储。两个常用的例子是ASCII和用于Unicode编码的UTF-8。根据Google的统计,UTF-8是目前最常用于网页的编码方式。相较于大部分的字符编码把字符对应到数字或比特串
IO流常用基类:
字节流的抽象基类:InputStream ,OutputStream
字符流的抽象基类:Reader ,Writer
由这四个类派生出来的子类名称都是以其父类名作为子类名的后缀
如:InputStream的子类FileInputStream。
如:Reader的子类FileReader。
编程:
- java.lang.Object
- java.io.Writer
- java.io.OutputStreamWriter
- java.io.FileWriter
- Constructors:
- Constructors:
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();
}
}
}
}
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 iftrue
, then data will be written to the end of the file rather than the beginning.
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();
}
}
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();
}
}
Methods inherited from class java.io.Writer
append, append, append, write, write
void
write(String str)
Writes a string.
Methods inherited from class java.io.OutputStreamWriter
close, flush, getEncoding, write, write, write
void
flush()
Flushes the stream.
void
close()
Closes the stream, flushing it first.
void
write(int c)
Writes a single character.
1 0
- IO概述
- IO概述
- Java IO 概述
- IO流(File概述)
- IO流概述
- 文件IO概述
- IO流概述
- 输入输出(IO概述)
- Java IO概述
- IO流-概述-FileWriter
- Java IO 概述
- IO流--概述
- 10026---IO流--概述
- JAVA IO概述
- Java IO概述
- IOの概述
- IO流解析概述
- 一、java io 概述
- ubuntu下建立Matlab快捷方式
- SDL init failure, reason is: No available video device: On Ubuntu64
- Ubuntu14.04无法调节屏幕亮度
- 第二章作业
- IMS SIP相关的Android终端的想法----来自实验室好友王阳
- IO概述
- NSDictionary、NSMutableDictionary的基本用法
- 项目经理人际关系技能
- 猫猫学IOS(十四)UI之UITableView扩充_表格的修改_(增删移动)
- C# 值类型和引用类型
- Python2.x和3.x主要差异总结
- 用struct模块实现python socket收发自定义TCP包
- java延时设置
- struts1.3中<struts-config>报错