Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3786584
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:42:23+00:00 2026-05-19T11:42:23+00:00

for (String name : filenames) { FileInputStream in = new FileInputStream(input.readUTF()); int byteCounter =

  • 0
    for (String name : filenames) {   
FileInputStream in = new FileInputStream(input.readUTF());   
    int byteCounter = 0;   
    int rowCounter = 0;   
    long bufferCounter = 0;   
    byte[] b = new byte[8];   
    int read;   

    //in.skip(10);   
    //while((read = in.read()) != -1){   
    while((read = in.read(b, 0, 10)) != -1){   
        byteCounter ++;   
        if (byteCounter != 1000){   
            if (rowCounter == 16){   
                System.out.println("\n");   
                rowCounter = 0;   
            }   
        System.out.print(Integer.toHexString(read) + "\t");   
            bufferCounter ++;   
            rowCounter ++;   
        }else{   
                byteCounter = 0;   
                try{   
                    Thread.sleep(200);   
                }catch(InterruptedException e) {   
                }   
        }   
    }   
    System.out.println("\n"+"================"+"\n");   
}  

Hi there, I was hoping someone might be able to help me with an issue I’ve been having. I’m trying to get my program to read in the first 10 bytes of a specified file. I can get it to work with the skip() but obviously this does the opposite of what I want (it removes the first 10 instead)
I’ve looked all over to no avail, if you can help me out, that’d be great.
You can probably see that I’ve tried to enter the read(b, off, len) into the code already but this just produces random characters as an output rather than the actual hex characters I want 74 65 71 etc (Edit: These random characters seem to be the hex code for the number of bytes read. So for a text file that has 23 hex chars in it, it produces a a 3 (or in other words: 10,10,3 = 23)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T11:42:24+00:00Added an answer on May 19, 2026 at 11:42 am

    the problem is here

    System.out.print(Integer.toHexString(read) + "\t");
    

    read contains the number of bytes effectively read from stream. Teh bytes are in array b.

    By the way: your array has a size of 8. you should increas it to 10 if you want to read 10 bytes!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So from this string: name[id] I need this: id I used str.split ('[]'), but
Has anyone else seen people do this: private string _name; public string Name{ get{
I have this class called Table: class Table { public string Name { get
When you call DbConnection.GetSchema you give it the string name of a collection you
I'd like to return an object with the following signature class AnonClass{ string Name
given the following class ... public class Category { public string Name {get;set;} public
Is there any way to format a string by name rather than position in
Given the following Flash method: function sendToJava(name:String, ... args) { ExternalInterface.call(sendCommand, name, args); }
This is what I have written: if ((lstProperty[i].PropertyIdentifier as string).CompareTo(Name) == 0) Resharper put
Lets say I have the following code: abstract class Animal case class Dog(name:String) extends

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.