i 绝望

依然

Miss Lang

java中I/O类

总结:输入流/输出流

方法,变量;

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
 * 
 * }
 * 
 * }
 */

  

posted on 2013-11-10 20:18  juewang  阅读(222)  评论(0编辑  收藏  举报

绝望依然

Miss Lang