This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes It doesnot print the content the file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "It doesnot print the content the file" Watch "It doesnot print the content the file" New topic
Author

It doesnot print the content the file

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 602


This code does not print!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16695
    
  19


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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3050
    
    1

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

Joined: Sep 06, 2007
Posts: 602


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
Sheriff

Joined: Sep 28, 2004
Posts: 16695
    
  19

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

Joined: Sep 06, 2007
Posts: 602


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
Sheriff

Joined: Sep 28, 2004
Posts: 16695
    
  19

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

Joined: Mar 28, 2003
Posts: 10816
    
  25

BeForthrightWhenCrossPostingToOtherSites (other topic)


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 602
I appreciate henry,But I need the answer.

and also Happy Christmas!! all!
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 2782
    
    2
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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: It doesnot print the content the file
 
Similar Threads
When to use flush() in Java?
how to solve this type of stackoverflowerror...
error in struts program
No main class
Iterating through a String.