Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

It doesnot print the content the file

 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This code does not print!
 
Henry Wong
author
Marshal
Pie
Posts: 21115
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You need to get into the habit of avoiding stuff like this...



If an error occurs, you will never know it since the application will just catch it and do nothing.

Henry
 
Stephan van Hulst
Bartender
Pie
Posts: 5796
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, you don't have to check whether a file exists and create it separately. If you're using a FileOutputStream, it will automatically create the file. You can get rid of lines 25 and 26.

The problem is that you're forgetting to flush your output. The data you've written is still in memory.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


still has problem:



run:
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'i'
at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2605)
at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2633)
at java.util.Formatter.parse(Formatter.java:2479)
at java.util.Formatter.format(Formatter.java:2413)
at java.io.PrintStream.format(PrintStream.java:920)
at fiedata.Main.main(Main.java:42)
Java Result: 1


 
Henry Wong
author
Marshal
Pie
Posts: 21115
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stacktrace describes it all, you just need to learn how to read it.

abalfazl hossein wrote:
run:
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'i'
at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2605)
at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2633)
at java.util.Formatter.parse(Formatter.java:2479)
at java.util.Formatter.format(Formatter.java:2413)
at java.io.PrintStream.format(PrintStream.java:920)
at fiedata.Main.main(Main.java:42)
Java Result: 1



On line 42, of your program (Main.java), you are calling the format() method; And this method is encountering an "unknown format" specified as "%i". And if look at the JavaDocs...

http://download.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html

You will see that there is no such format.

Henry
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


still has problem:

run:
java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:375)
at fiedata.Main.main(Main.java:40)

 
Henry Wong
author
Marshal
Pie
Posts: 21115
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abalfazl hossein wrote:
still has problem:

run:
java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:375)
at fiedata.Main.main(Main.java:40)




No offense, but isn't it time to, at least, try to solve the problem yourself? For example, did you even try to look up what an "EOF" means?

Henry
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11878
195
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BeForthrightWhenCrossPostingToOtherSites (other topic)
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I appreciate henry,But I need the answer.

and also Happy Christmas!! all!
 
Mike Simmons
Ranch Hand
Posts: 3076
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well if you need the answer, it will help a lot to ShowSomeEffort. This is beneficial two ways: it makes people here more willing to help you, and you might learn something.

As a hint: java.io.EOFException is a class in the standard Java library. It's documented like (almost) any standard Java class, in the Java API. In fact the forum software here has helpfully converted the phrase " java.io.EOFException " into a link. If you click on that link, you can get some clue as to what the problem is. If you don't understand it, all right, ask us for more help, and we're here. But please try to type something that shows you've done some work of your own (such as looking up java.io.EOFException to find out what it means).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic