标签:void exception input logs div 复制粘贴 family des font
import java.io.*; public class Copy1M { public static void main(String arg[]) throws FileNotFoundException{ long begin = System.currentTimeMillis(); //记录程序开始事件 //**************************************获取文件属性******************************************************** //创建File 对象f1,以调用其属性 File f1 = new File("D:\\Desktop\\copytext\\设计模式.avi"); //判断文件设计模式.avi是否存在 boolean a = f1.exists(); if(a){ System.out.println("确认文件设计模式.avi"); }else{ System.out.println("文件不存在,无法读取"); } //获取文件长度 int length = (int)f1.length(); System.out.println("文件长度:"+length); //**************************************读取文件******************************************************** //创建读取文件对象 FileRead FileInputStream FileRead = new FileInputStream("D:\\Desktop\\copytext\\设计模式.avi"); byte[] b = new byte [length]; //创建数组 //将文件一次性读到数组中 try { FileRead.read(b); System.out.println(b); FileRead.close(); } catch (IOException e) { e.printStackTrace(); } // for(len = 0; len < length;len++){ // System.out.print((char)len); // try { // FileRead.close(); // } catch (IOException e) { // // TODO 自动生成的 catch 块 // e.printStackTrace(); // } // } //**************************************写入文件******************************************************** FileOutputStream FileWrite = new FileOutputStream("D:\\Desktop\\设计模式.avi"); try { FileWrite.write(b); FileWrite.close(); } catch (IOException e) { e.printStackTrace(); } long end = System.currentTimeMillis() - begin; // 记录程序结束事件 System.out.println("耗时:" + end + "毫秒"); } }
标签:void exception input logs div 复制粘贴 family des font
原文地址:http://www.cnblogs.com/string9527/p/7157405.html