zoukankan      html  css  js  c++  java
  • Java&IO

    输入流和输出流相对于内存设备而言.
     
    将外设中的数据读取到内存中:输入
    将内存的数写入到外设中:输出。
     
    字符流的由来:
    其实就是:字节流读取文字字节数据后,不直接操作而是先查指定的编码表。获取对应的文字。
    在对这个文字进行操作。简单说:字节流+编码表 
     
    ---------------------------------------
     
    字节流的两个顶层父类:
    1,InputStream  2,OutputStream.
     
    字符流的两个顶层父类:
    1,Reader 2,Writer
    /*
     * 写数据到文件
     */
    public class Client1 {
    
        private static final String LINE_SEPARATOR = System.getProperty("line.separator");
        
        public static void main(String[] args){
    
            FileWriter fw = null;
            try {
                fw = new FileWriter("E:\test\Demo02\demo.txt");
                
                fw.write("12314541251541aaaaa" + LINE_SEPARATOR + "sffdsfsdfew");
                
                fw.write("xxxxxxxxxxx");
                
            } catch (IOException e) {
                e.printStackTrace();
            } finally
            {
                if(fw != null)
                {
                    try {
                        fw.flush();
                        fw.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }            
            }
        }
    }
    
    
    /*
     * 从文件读取数据
     */
    public class Client2 
    {
    
        public static void main(String[] args) 
        {
            StringBuilder sb = new StringBuilder();
            char[] chs = new char[1024];
            try {
                FileReader fr = new FileReader("demo.txt");
                int num = 0;
                try {
                    while((num = fr.read(chs)) != -1)
                         sb.append(new String(chs,0,num));
                    
                } catch (IOException e) {
                    e.printStackTrace();
                }
                
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            
            System.out.println(sb.toString());
    
        }
    
    }

     

  • 相关阅读:
    fiddler配置及使用教程
    获取字符串中出现次数最少的字符
    引用数据类型的深拷贝
    jquery一些方法
    常用字体
    图片模拟
    返回上一页并刷新
    移动端网页调试神器
    input一些限制
    使用transform后z-index失效的解决方法
  • 原文地址:https://www.cnblogs.com/xiarongjin/p/8310803.html
Copyright © 2011-2022 走看看