The use of BufferedInputStream/BufferedOutputStream.
If we copy a file.
1.input the file
2.OS RAM
3.JVM RAM
4.code
5.JVM RAM
6.OS RAM
7.ouput the file
So many procedures,it's why that the copy a file cost so much time.
If we use the buffer the files will fisrt store in the JVM RAM.Then send to the code at one time.
It just like a car send one package at one time.With buffer,you can use the car send many package at one time.So efficent it is.
public static void writeContent(String path) throws IOException{
//实例化一个输出流对象
FileOutputStream fos = new FileOutputStream(path,ture);
BufferedOutputStream bos = new BufferedOutputStream(fos);
String [] array = {"a","b","c","d","e","f"};
//系统会自己给你一个默认的大小缓冲空间,
for(int i=0;i<array.length;i++){
bos.write(array[i].charAt(0)); //把字符串改成字符
}
System.out.println("文件写入成功!");
bos.flush();
bos.close();
fos.close();
}
//只能将支持 java.io.Serializable 接口的对象写入流中。每个 serializable 对象的类都被编码,编码内容包括类名和类签名、对象的字段值和数组值,以及从初始对象中引用的其他所有对象的闭包。
The serialization of the object
If we want to I/O a object.We should let the
class interface serializable .
The java.io.ObjectInputStream class's void writeOject(Object obj) method to input a object.The same as Output.
Under some special condition,If you want to keep the class's attributes as secrets.Just add the key word transient(短暂的).The system won't store the attribute when input.
private static void writeObject(String string) throws IOException, ClassNotFoundException {
student st=new student("张三",5);
//实例化一个输出流对象
FileOutputStream fos = new FileOutputStream("src/xy_进阶的IO流0909/student.txt");
//实例化一个对象流对象
ObjectOutputStream oos=new ObjectOutputStream(fos);
//写入对象
oos.writeObject(st);
//强制写入对象流
oos.flush();
//关闭对象流
oos.close();
//实例化一个输入流对象
FileInputStream fis = new FileInputStream("src/xy_进阶的IO流0909/student.txt");
//实例化一个对象流对象
ObjectInputStream ois=new ObjectInputStream(fis);
//需要强制转型
student st1=(student)ois.readObject();
System.out.println(st1.getName());
}
分享到:
相关推荐
顶点缓存数组(Vertex Buffer Object)的示例程序 VBO允许把顶点数据存储在GPU缓存中,并且只传输一次,前提是有足够的内存资源可以保存这些顶点数据。
Storage and Buffer Manager实现文档
使用最新的opengl扩展fbo编写的程序,该扩展提供了替代pbuffer的功能,使MRT的实现更加方便。使用vc6和ogl2.0编写。
个人总结的VLC对于input buffer管理的分析,希望对大家有用,顺便赚点分数^_^
Buffer Overflow Attacks and Defenses
Storage and Buffer Manager C++ code.在别人的基础上做的,应该说除了lru都是重做的.模拟数据库文件的实现.
数据库功能模拟Storage and Buffer Manager C++实现
Buffer Overflows and You
Storage and Buffer Manager实现
JAVA实现模拟数据库部分功能Storage and Buffer Manager
Lock-free Queue and Ring Buffer
C语言头文件 BUFFERC语言头文件 BUFFERC语言头文件 BUFFERC语言头文件 BUFFERC语言头文件 BUFFERC语言头文件 BUFFERC语言头文件 BUFFERC语言头文件 BUFFERC语言头文件 BUFFERC语言头文件 BUFFERC语言头文件 BUFFERC...
CHANGES: * V1.5 * + 修正indent[aaa,bbb] 的问题 ,后面没换行的问题,主要是美化。 ... * V1.4 * + 修正D7下关闭溢出出错的问题{.$.Q-} ... * + Null Object Design Patern (ex: for obj in values.N['path'] do ...)
CMOS和TTL -- EDN电子设计技术.pdfCMOS和TTL -- EDN电子设计技术.pdf
安装方便,简易客户端使用
Buffer and delay relay system
socket no buffer available,using delphi ICS and java socket
npm i -S buffer-backed-object为什么?网络工作者使用,通常需要考虑postMessage() (或确切地说是postMessage()的性能。尽管,但它有时仍会成为瓶颈,尤其是在负载较大的情况下。 及其的克隆速度非常快(甚至可以...
Get an easy introduction to reactive streams in Java to handle concurrency, data streams, and the propagation of change in today's applications. This compact book includes in-depth introductions to ...
According to the measurement results of the proof-of-concept prototypes, the proposed techniques are able to reduce the design overhead of the front-end and reference buffer and improve the ADC ...