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 9185689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:20:17+00:00 2026-06-17T19:20:17+00:00

I’m a newbie so the only ways to read a file in Java I

  • 0

I’m a newbie so the only ways to read a file in Java I know are:

DataInputStream dis = new DataInputStream(new FileInputStream(<FILE>));

and:

BufferedReader br = new BufferedReader(new FileReader(<FILE>));

And I know that while the first one serves the purpose of handling binary files, the latter is used for character/text files (for my current understanding: such that I can open them with, say, notepad and see something a human can actually read). The problem is: what if the problem does not state whether I’m to deal with a binary or text file? I mean: when I’m to read an object from a file, for example, I know it’s the first, but what when I’m only given info like “Your method is to read from the file XYZ which contains names of the students which you are to process (and so on and so on)”?

I’ve come across some such tasks and was never sure which one to use. Can I use whatever I want if the description doesn’t explicitly state the type of the file or is there some convention that if nothing is said, it’s safer to assume we’re dealing with X?

  • 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-06-17T19:20:19+00:00Added an answer on June 17, 2026 at 7:20 pm

    You do need to know which type you want to read.

    If the spec is unclear, define (and document) it for yourself. If you already have an existing file, you can have a look at it to decide which approach to take – if it is line oriented, with no “unreadable” characters in it, e.g. one name at a line, you would take the text file approach. If it looks strange when opened in a text editor, you can assume a binary file, but in this case you need additional information anyways to be able to correctly read it.

    On a file system level, there is no such thing like “binary” or “text” file – it depends on how you interpret it. You can read each file as a binary file (considering the individual bytes – this is what hex editors do), and you can read (almost) each file as text (and most likely end up with something which looks like garbage when you try to print it). (I said “almost” since there are some constraints with multibyte characters, where one character is built from more than one byte. But even these files could still be treated as “extended ASCII” files where each byte maps to exactly one character).

    In any case, you should document the file format you expect (even “text” files can have different structures, like fixed line length, variable line length and so on).

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

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.