您现在的位置是:主页 > news > 网站必须备案/互联网营销培训
网站必须备案/互联网营销培训
admin2025/6/26 5:41:12【news】
简介网站必须备案,互联网营销培训,住房建设厅的网站首页,网站建设 事业单位 安全读写文件一个流被定义为一个数据序列。输入流用于从源读取数据,输出流用于向目标写数据。输入流和输出流的类层次图。FileInputStreamFileInputStream用于从文件中读取数据,它的对象可以用关键字new创建,InputStream file new FileInputStream("D:…
读写文件
一个流被定义为一个数据序列。输入流用于从源读取数据,输出流用于向目标写数据。
输入流和输出流的类层次图。
FileInputStream
FileInputStream用于从文件中读取数据,它的对象可以用关键字new创建,
InputStream file = new FileInputStream("D:\BI\201603\MyBi");
或者
File file = new File("D:\BI\201603\MyBi");
InputStream file = new FileInputStream(f);
InputStream提供的对流的操作的方法:
序号方法及描述
1
public void close() throws IOException{}
关闭此文件输入流并释放与此流有关的所有系统资源。抛出IOException异常。
2
protected void finalize()throws IOException {}
这个方法清除与该文件的连接。确保在不再引用文件输入流时调用其 close 方法。抛出IOException异常。
3
public int read(int r)throws IOException{}
这个方法从InputStream对象读取指定字节的数据。返回为整数值。返回下一字节数据,如果已经到结尾则返回-1。
4
public int read(byte[] r) throws IOException{}
这个方法从输入流读取r.length长度的字节。返回读取的字节数。如果是文件结尾则返回-1。
5
public int available() throws IOException{}
返回下一次对此输入流调用的方法可以不受阻塞地从此输入流读取的字节数。返回一个整数值。
FileOutputStream
FileInputStream用来创建一个文件并向文件中写数据。如果目标文件不存在,该流回创建文件。
OutputStream f = new FileOutputStream("D:\BI\201603\MyBi");
或者
File file = new File("D:\BI\201603\MyBi");
OutputStream f = new FileOutputStream(file);
OutputStream类提供了一下方法操作文件
序号方法及描述
1
public void close() throws IOException{}
关闭此文件输入流并释放与此流有关的所有系统资源。抛出IOException异常。
2
protected void finalize()throws IOException {}
这个方法清除与该文件的连接。确保在不再引用文件输入流时调用其 close 方法。抛出IOException异常。
3
public void write(int w)throws IOException{}
这个方法把指定的字节写到输出流中。
4
public void write(byte[] w)
把指定数组中w.length长度的字节写到OutputStream中。
原文:http://www.cnblogs.com/blackheartinsunshine/p/6022578.html