Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Input/Output Problem

 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This type of small snippets, you can easily find on the Java Developers Almanac.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49405
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it really is a .txt file, have you tried java.util.Scanner?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic