Buffer and Object input and out put_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Buffer and Object input and out put

Buffer and Object input and out put

 2013/9/10 22:06:32  xuyi1994  程序员俱乐部  我要评论(0)
  • 摘要:TheuseofBufferedInputStream/BufferedOutputStream.Ifwecopyafile.1.inputthefile2.OSRAM3.JVMRAM4.code5.JVMRAM6.OSRAM7.ouputthefileSomanyprocedures,it'swhythatthecopyafilecostsomuchtime.IfweusethebufferthefileswillfisrtstoreintheJVMRAM
  • 标签:
  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.
class="java">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.
  • 相关文章
发表评论
用户名: 匿名