File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes BigInteger back to text 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 » Java in General
Reply Bookmark "BigInteger back to text" Watch "BigInteger back to text" New topic
Author

BigInteger back to text

Stan Wilson
Greenhorn

Joined: Aug 19, 2004
Posts: 4
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

Joined: Aug 02, 2004
Posts: 823
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

    Joined: Dec 10, 2001
    Posts: 7023
    Moving this to the Intermediate forum...


    [How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
     
    I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
     
    subject: BigInteger back to text
     
    Similar Threads
    int to byte[]
    BigInteger(String val, int radix) not working?
    Custom Converter - Java Studio Creator
    Multiplying Byte Arrays.
    Help! Question on converting String to BigInteger