V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
tedzhou1221
V2EX  ›  Java

FileInputStream 读取文件的问题

  •  
  •   tedzhou1221 · 2023-03-03 19:22:03 +08:00 · 505 次点击
    这是一个创建于 434 天前的主题,其中的信息可能已经有所发展或是发生改变。

    例子:

     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 怎么知道下一次循环,从文件的哪个位置开始读呢?

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

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3180 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 14:18 · PVG 22:18 · LAX 07:18 · JFK 10:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.