• Post Reply Bookmark Topic Watch Topic
  • New Topic

HELP!!!

 
Eric Larsen
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote this program to:

1. Write "Text to be hashed." to unhashed.txt
2. Read it back from unhashed.txt with a FileInputStream chained to a BufferedInputStream
3. Print the result to the screen.
4. Create a SHA-1 digest of it.
5. Print the digest to the screen.
6. Write the digest to hashed.txt

The class compiles and runs without any errors, but I do not get the desired output. unhashed.txt is created, but is empty, hashed.txt is not created, and the result of step two is not printed. The digest is printed to the screen, however. Any help would be very much appreciated.

The class source:



The screen output:

 
Ryan Beckett
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Close your I/O streams.
 
Eric Larsen
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Ryan!

I revised the code to:

1. flush the buffers before switching I/O tasks, either by closing the stream, or flushing it manually.
2. create a new BufferedWriter for the second .txt file and assigning it to the old reference.

It now works exactly as intended. Thanks for the help!

Revised source:



 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/UseAMeaningfulSubjectLine
"HELP!!!" is definitely not meaningful.
 
Eric Larsen
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I forgot to change it before I hit "submit." I'll do better next time.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!