总结:输入流/输出流

方法,变量;

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

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-06
  • 2021-10-05
  • 2021-09-09
  • 2021-04-16
  • 2021-07-23
猜你喜欢
  • 2021-09-10
  • 2021-03-31
  • 2022-12-23
  • 2021-08-07
  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案