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();
                }
            }
            
            
        }
    }
  • 相关阅读:
    hdu 4525(数学)
    hdu 4524(模拟)
    hdu 4523(大整数)
    hdu 4517(递推枚举统计)
    hdu 4520
    hdu 4519(数学题)
    hdu 4514(树的直径+并查集)
    hdu 4510(模拟)
    hdu 2089(数位DP)
    hdu 4506(数学,循环节+快速幂)
  • 原文地址:https://www.cnblogs.com/frost-yen/p/5387123.html
Copyright © 2011-2022 走看看