zoukankan      html  css  js  c++  java
  • Java他们其中一个IO(一)

    1.I/O 操作的目标

    其中从数据源读取数据,和写数据到的目标位置数据。


    2.IO 的分类方法

    以下是个核心类是字节流的核心类

    InputStream、OutputStream 是抽象类


    3.读取文件和写入文件的方法

    读取数据用read方法 int read(byte [] b, int off, int len)   第一个參数是byte类型的数组;第二个參数是偏移量 eg); 数组是 0,1。2,3,4,5。6  off是5的话要从5開始写;第三个參数是长度

    void write (byte [] b, int off , int len) off是5的话前面的就不要了,要从第五个開始写;len是要写入的长度


    eg):

    //第一步骤:导入类;

    import java .io.*;

    class Test {

    public static void main (String args [] ) {

    //声明输入流应用

    FileInputStream fis = null;

    //声明输出流的引用

    FileOutputStream fos = null;

    try {

    //声明代表输入流的对象

    fis = new FileInputStream ("e:/src/from.txt");

    //声明代表输出流的对象

    fos = new FileOutputStream ("e:/src/to.txt");

    //生成一个字节数组

    byte [] buffer = new byte [100];

    //调用输入流对象的read方法,读取数据

    int temp = fis.read (buffer, 0,buffer.length);

    fos.write (buffer,0,temp);

    //String s = new String (buffer);

    //调用一个String 对象的 trim 方式,将会去除掉这个字符串的首尾空格和空字符

    //s = s.trim ();

    //System.out.println (s);


    }

    catch (Exception e) {

    System.out.println (e);

    }

    }

    }




    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    在线图片压缩
    wiki-editor语法
    Android 4.0.4模拟器安装完全教程(图文)
    Javascript中的void
    守护进程
    jQuery编程的最佳实践
    JavaScript内存优化
    vim编程技巧
    MySQL表的四种分区类型
    SQL中的where条件,在数据库中提取与应用浅析
  • 原文地址:https://www.cnblogs.com/blfshiye/p/4813743.html
Copyright © 2011-2022 走看看