zoukankan      html  css  js  c++  java
  • Java例程练习(字节流)

    import java.io.*;
    
    public class Test {
    	public static void main(String[] args) {
    		int b = 0;
    		FileInputStream in = null;
    		
    		try {
    			
    			in = new FileInputStream("C:/java/Test.java");
    			
    		} catch (FileNotFoundException e) {
    			System.out.println("找不到指定文件");
    			System.exit(-1);
    		}
    		
    		try {
    			
    			long num = 0;
    			while((b = in.read()) != -1) {
    				System.out.print((char)b);
    				num ++;
    			}
    			
    			in.close();
    			System.out.println();
    			System.out.println("共读取了" + num + " 个字节");
    			
    		} catch (IOException e) {
    			System.out.println("文件读取错误");
    			System.exit(-1);
    		}
    		
    		
    	}
    }
    
    import java.io.*;
    
    public class Test {
    	public static void main(String[] args) {
    		int b = 0;
    		FileInputStream in = null;
    		FileOutputStream out = null;
    		
    		try {
    			in = new FileInputStream("C:/java/Test.java");
    			out = new FileOutputStream("C:/java/A/HW.java");
    
    			while((b = in.read()) != -1) {
    				out.write(b);
    				
    			}
    			
    			in.close();
    			out.close();
    		} catch (FileNotFoundException e) {
    			System.out.println("找不到指定文件");
    			System.exit(-1);
    		} catch (IOException e) {
    			System.out.println("文件复制错误");
    			System.exit(-1);
    		}
    		
    		System.out.println("文件已复制");
    		
    	}
    }
    


    
    
    
    
    
  • 相关阅读:
    工业互联网兴起
    互联网经济学
    广泛应用的区块链技术
    工业互联网数据传输探讨
    谈谈网站性能
    深入探讨vue响应式原理
    工业互联网虚拟数字
    对www.518shengmao.com站资源打包,采用vue Node.js
    jquery的事件命名空间详解
    巧用索引与变量
  • 原文地址:https://www.cnblogs.com/wjchang/p/3671704.html
Copyright © 2011-2022 走看看