Reading the first 10 bytes of a file in Java

后端 未结 2 1210
挽巷
挽巷 2021-01-22 09:32
    for (String name : filenames) {   
FileInputStream in = new FileInputStream(input.readUTF());   
    int byteCounter = 0;   
    int rowCounter = 0;   
    long buff         


        
2条回答
  •  无人及你
    2021-01-22 10:38

    byte[] b = new byte[10];
    new DataInputStream(new FileInputStream(input.readUTF())).readFully(b);
    

    This is the simplest way, but it throws in case there are less than 10 bytes available. In case you don't want it, use a loop. Somehow I don't get what you're doing, it really doesn't look like reading the first 10 bytes: if (byteCounter != 1000)

提交回复
热议问题