• Post Reply Bookmark Topic Watch Topic
  • New Topic

BigInteger back to text  RSS feed

 
Stan Wilson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am doing some Encryption type studies and have encrypted then decrypted ok( I think). I am struggling to get what was initially a simple text file converted to byte then BigInteger, back to the same presentable text.

Can someone advise a process from BigInteger to a file save state.
What I have tried with all sorts of variations is from BigInteger, to byte [] via the toByteArray() method then String = new String(byte)..but still have all munched up characters when I view the file..

Any help appreciated.
[ August 20, 2004: Message edited by: Stan Wilson ]
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stan,

Since you have a text file it makes more sense to use the BigInteger(String) constructor. Try the following steps:
  • Read in file using FileReader wrapped in BufferedReader (use getLine() method - assuming you have one BigInteger per line in the file)
  • Create a new BigInteger with the String constructor
  • Perform whatever operation you require
  • Write the result back to the text file using FileWriter/BufferedWriter and BigInteger.toString()


  • No mangling should occur.

    Hope that's useful.

    Jules
     
    Dirk Schreckmann
    Sheriff
    Posts: 7023
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Moving this to the Intermediate forum...
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!