zoukankan      html  css  js  c++  java
  • Java IO

    public class InputStreamTest2 {
    
    	public static void main(String[] args) throws IOException {
    		// TODO Auto-generated method stub
    		File file = new File("d:\data.txt");
    		InputStream in = new FileInputStream(file);
    		byte[] b = new byte[1024];
    		int off = 0;
    		
    		int len = b.length;
    		while((off=in.read(b, 0, b.length))!=-1){
    			System.out.println(new String(b,0,off));
    		}
    		in.close();
    	}
    
    }
    

    拷贝指定的文件:

    public class copyFileTest {
    
        public static void main(String[] args) throws IOException {
            // TODO Auto-generated method stub
            File src = new File("d:\data.txt");
            File desc = new File("d:\desc.txt");
            
            new copyFileTest().copyFile(src, desc);
        }
        public void copyFile(File src,File desc) throws IOException{
            FileInputStream in = new FileInputStream(src);
            FileOutputStream out = new FileOutputStream(desc);
            byte b[] = new byte[1024];
            int start=0;
            while((start=in.read(b, 0, b.length))!=-1){
                out.write(b, 0, start);
                out.flush();
            }
            in.close();
            out.close();
        }
    }

     字符流:

    public class ReaderWriterTest {
    
        public static void main(String[] args) throws IOException {
            // TODO Auto-generated method stub
            FileInputStream in = new FileInputStream("d:\reader.txt");
            FileOutputStream out = new FileOutputStream("d:\writer.txt");
            InputStreamReader isr = new InputStreamReader(in);
            OutputStreamWriter osw = new OutputStreamWriter(out);
            char b[] = new char[1024];
            int c;
            while((c=isr.read(b, 0, b.length))!=-1){
                String s = new String(b, 0, c);
                System.out.print(s);
                osw.write(b, 0, c);
                osw.flush();
            }
            isr.close();
            osw.close();
        }
    
    }
  • 相关阅读:
    给msde加装企业管理器
    InterBase 数据库与驱动 版本不同
    delphi 演示数据路径
    TNetHTTPClient 使用
    MYSQL之库操作
    MYSQL之数据操作
    MYSQL之表操作
    MYSQL之视图、触发器、存储过程、函数、事物、数据库锁和数据库备份
    数据库三范式详解
    MYSQL之索引原理与慢查询优化
  • 原文地址:https://www.cnblogs.com/james-roger/p/5681247.html
Copyright © 2011-2022 走看看