集册 Java实例教程 使用DataInputStream从文件读取字节数组

使用DataInputStream从文件读取字节数组

欢马劈雪     最近更新时间:2020-01-02 10:19:05

499
要从文件读取字节数组,请使用Java DataInputStream类的int read(byte b [])方法。
/*
来 自*
 N o w J a v a . c o m - 时代Java
*/

import java.io.DataInputStream;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;


public class Main {


  public static void main(String[] args) {


    String strFilePath = "C:/Folder/readByteArray.txt";


    try {
    /** 
    来 自 
    时代Java公众号 - N o w J a  v a . c o m
    **/

      FileInputStream fin = new FileInputStream(strFilePath);


      DataInputStream din = new DataInputStream(fin);


      byte b[] = new byte[10];

      din.read(b);


      din.close();


    } catch (FileNotFoundException fe) {

      System.out.println(
展开阅读全文