您的位置:首页 > 编程语言 > Java开发

java中I/O类

2013-11-10 20:18 260 查看
总结:输入流/输出流

方法,变量;

package com.aini;

//流类。输入输出流
import java.io.*;

public class rtyeew {// (File file)这里是方法传递参数的意思吗。
public static void copyFileByFileOutputStream(File file) throws IOException {
FileInputStream fis = null;// 复制
FileOutputStream fos = null;// 由于后面要关闭文件,所以这里要声明是null
byte[] b = new byte[204];
int length = 0;
try {
fis = new FileInputStream(file);// 向文件中读入数据
fos = new FileOutputStream(file.getName());//
while ((length = fis.read()) != -1) {
fos.write(b, 0, 203);
}
fos.flush();// 输出流刷新
} catch (Exception E) {
System.out.println("Error:" + file.getAbsoluteFile());// 这里是file的方法。不是异常对象。

} finally {

if (fis != null)
fis.close();
if (fos != null)
fos.close();
}
}
}

/*
* public static void main(String[] args) { rtyeew demo =new rtyeew();
* FileInputStream fis; FileOutputStream fos; try{ fis= new
* FileInputStream("log.xtx");//文件输入流创建对象需要分配内存空间 fos= new
* FileOutputStream("da.xtx");
* demo.copyFileByFileOutputStream(fis,fos);//这里也是一样是普通的方法调用,所以没有普通的方法,怎么
* }catch(Exception e){//调用出来。 System.out.println("Error:"+e); System.exit(-3);
* }
*
* } private void copyFileByFileOutputStream(FileInputStream fis,
* FileOutputStream fos) { // TODO Auto-generated method stub
*
* }
*
* }
*/


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: