zoukankan      html  css  js  c++  java
  • 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
     * 
     * }
     * 
     * }
     */
    

      

  • 相关阅读:
    chmod命令详细用法
    mysql删除sql表添加别名及删除sql的注意事项
    bootstrap栅格系统进行偏移格式
    mysql中时间计算函数SQL DATE_SUB()用法
    阿里图标的应用教程
    jquery.cookie.js中$.cookie() 使用方法
    $.cookie()取值设置
    java中年月日的加减法,年月的加减法使用
    IMAP命令与分析
    Telnet IMAP Commands Note
  • 原文地址:https://www.cnblogs.com/langlove/p/3417014.html
Copyright © 2011-2022 走看看