Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Still need some help w/ IO and Data Conversion  RSS feed

 
Tonia Billiot
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First let me apologize for all of the following code. It is not the whole program. I have a GUI (cardLayout) that allows a user to type in their company information (on 1st Panel) and totals (in 2nd Panel) for grocery & non grocery sales. I am having difficulty converting the sales and writing the information to a text document. I have looked at the online tutorials and the Java API; however, I am still lost on these issues and need some guidance.



Thanks for your assistance..

[ April 23, 2005: Message edited by: Tonia Billiot ]
[ April 24, 2005: Message edited by: Tonia Billiot ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tonia Billiot:
I am having difficulty converting the sales and writing the information to a text document.
Can you give us more information, please? That's a lot of code to trudge through without at least a good hint of where the problem lies. What happens when you run it? Do you get an exception or incorrect output? Post the stack trace or expected and actual output.
 
Tonia Billiot
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The system output is pretty extensive as well. Though I am pretty sure there is something wrong in the write file method. The program compiles and runs, but it is not writing to the file. Let me note that the java, class, and txt file are all in the same directory. I called the writeFile method from the actionPerformed method.
C:\Documents and Settings\MyDocuments\Java\salesTaxWizard>java Sales
TaxWizard
data.txt exists
The File is 0 bytes long
ok to read
ok to write
java.io.FileNotFoundException: C:\DocumentsandSettings\MyDocuments\Ja
va\salesTaxWizard\data.txt (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileWriter.<init>(Unknown Source)
at SalesTaxWizard.writeFile(SalesTaxWizard.java:228)
at SalesTaxWizard.actionPerformed(SalesTaxWizard.java:220)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknow
n Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
java.io.FileNotFoundException: C:\DocumentsandSettings\MyDocuments\Ja
va\salesTaxWizard\data.txt (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileWriter.<init>(Unknown Source)
at SalesTaxWizard.writeFile(SalesTaxWizard.java:228)
at SalesTaxWizard.actionPerformed(SalesTaxWizard.java:220)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknow
n Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
[ April 24, 2005: Message edited by: Tonia Billiot ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tonia Billiot:
java.io.FileNotFoundException: C:\DocumentsandSettings\MyDocuments\Ja
va\salesTaxWizard\data.txt (The system cannot find the path specified)
Why are the spaces in "Documents and Settings" being removed? Is this due to cut-n-paste to post or is that really what the exception message says? If the latter, how is it getting munged when you're not even providing the path to it? Very strange.

You might want to create a File from the name before creating the FileWriter. Then print out the full canonical path to the file to make sure it's correct.
 
Tonia Billiot
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"I am sure glad this forum exists. Thanks to you,David, I realized that I had a typo. I did not type the spaces into the program. After reading your message and going back to give your suggestion a try, I noticed that I left out the spaces. I typed in the spaces and the massive error message disappeared." Posted before realization..

Ok, After posting this message, I realized that initially I did not type out the path in the above posted program. After posting the code the above code, I typed in the full path w/out the spaces into my copy of the program. After David's suggestion, I added the spaces and now am getting the correct info in the text document.
Note: I was rambling...Good Night.
THANK YOU, DAVID
[ April 24, 2005: Message edited by: Tonia Billiot ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to help. And welcome to JavaRanch!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!