Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Java in General and the fly likes Input/Output Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Input/Output Problem " Watch "Input/Output Problem " New topic

Input/Output Problem

Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
I have written a program to get the input from a file using DataInputStream and display it on console. The Program is as follows:

The problem that is coming is the output on the console is not human readable. Please tell where i am going wrong.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
DataInputStream is not meant for reading clear text (which is what you're doing, judging from the filename). Leave it out and use the BufferedInputStream directly, or -even better- wrap it in a BufferedReader that allows you to read line by line.
bart zagers
Ranch Hand

Joined: Feb 05, 2003
Posts: 234
This type of small snippets, you can easily find on the Java Developers Almanac.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46375
If it really is a .txt file, have you tried java.util.Scanner?
I agree. Here's the link:
subject: Input/Output Problem
It's not a secret anymore!