• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

HELP!!!

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Close your I/O streams.
 
Eric Larsen
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:



 
Sheriff
Posts: 22662
127
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I forgot to change it before I hit "submit." I'll do better next time.
 
reply
    Bookmark Topic Watch Topic
  • New Topic