集册 Java实例教程 使用InputStream非缓冲流逐字节读取

使用InputStream非缓冲流逐字节读取

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

578
使用InputStream非缓冲流逐字节读取

import java.io.IOException;

import java.io.InputStream;

import java.nio.file.Files;

import java.nio.file.Path;//N o w J a v a . c o m - 时代Java 提供

import java.nio.file.Paths;


public class Main {

  public static void main(String[] args) {

    Path path = Paths.get("C:/folder1/equipment", "test.txt");


    int n;

    byte[] in_buffer = new byte[1024];

    try (InputStream in = Files.newInputStream(path)) {

      while ((n = in.read(in_buffer)) != -1) {

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