zoukankan      html  css  js  c++  java
  • [Java] 读写字符串数据

    package test.stream;
    
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    /**
     * 读写字符串数据
     * @author Frost.Yen
     * @E-mail 871979853@qq.com
     * @date 2016年4月13日
     */
    public class TestWriteData01 {
        public static void main(String[] args) {
            FileOutputStream fos = null;
            FileInputStream fis = null;
            try {
                fos = new FileOutputStream("E:\JAVA\Examples\To Learn\src\test\stream\data.dat");
                String hello = "hello world";
                byte[] buf = hello.getBytes();
                fos.write(buf, 0, buf.length);
                
                String str = String.valueOf(12024568);
                fos.write(str.getBytes(), 0, str.getBytes().length);
                str = String.valueOf(13);
                fos.write(str.getBytes(), 0, str.getBytes().length);
                str = String.valueOf(28);
                fos.write(str.getBytes(), 0, str.getBytes().length);
                
                fis = new FileInputStream("E:\JAVA\Examples\To Learn\src\test\stream\data.dat");
                byte[] buf1 = new byte[1024];
                int len = 0;
                while((len = fis.read(buf1))>=0){
                    System.out.write(buf1, 0, len);
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }finally {
                try {
                    if(fos!=null) fos.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                try {
                    if(fis!=null) fis.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            
            
        }
    }
  • 相关阅读:
    三数之和
    罗马数字与整数
    Oracle 开启或关闭归档
    Oracle RMAN scripts to delete archivelog
    Oracle check TBS usage
    Oracle kill locked sessions
    场景9 深入RAC运行原理
    场景7 Data Guard
    场景4 Data Warehouse Management 数据仓库
    场景5 Performance Management
  • 原文地址:https://www.cnblogs.com/frost-yen/p/5387123.html
Copyright © 2011-2022 走看看