tedzhou1221
V2EX  ›  Java

FileInputStream 读取文件的问题

  •  
  •   tedzhou1221 · Mar 3, 2023 · 1042 views
    This topic created in 1197 days ago, the information mentioned may be changed or developed.

    例子:

     public static void main(String[] args) throws IOException {
            FileInputStream fileInputStream = new FileInputStream(new File("/data/text.txt"));
            byte[] bytes = new byte[1024];
            while (fileInputStream.read(bytes) != -1) {
                System.out.println(new String(bytes));
            }
        }
    

    FileInputStream 读取文件时,循环每次读取 byte[1024]大小的数据。

    请问 JVM 怎么知道下一次循环,从文件的哪个位置开始读呢?

    是否有一个位置指针的变量?我在源码里没有找到。请教一下大佬们。谢谢

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   896 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 21:59 · PVG 05:59 · LAX 14:59 · JFK 17:59
    ♥ Do have faith in what you're doing.