aspose file tools*
The moose likes Java in General and the fly likes File encryption / decryption retaining line feeds Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "File encryption / decryption retaining line feeds" Watch "File encryption / decryption retaining line feeds" New topic
Author

File encryption / decryption retaining line feeds

P White
Greenhorn

Joined: Dec 28, 2011
Posts: 10
Hi,

Can someone please point me in the right direction. I have been at this all day and am no closer to a solution than I was first thing this morning.

I have written a simple quiz program that reads its information form a csv file. I would like to encrpt the data as the csv file indicates which asnwer is correct.

When I encrypt and decrypt the csv file I am losing any line feeds in the file which messes up the formating of the text in my text areas.

I don't know why perhaps someone would point me in the right direction.

File encryptor:


P White
Greenhorn

Joined: Dec 28, 2011
Posts: 10
and this is the decryptor so that you get your csv file back.

P White
Greenhorn

Joined: Dec 28, 2011
Posts: 10
I have found a work around to this now.

I am reading the quiz file and replacing the \r\n with a seldom used character and the \n with another seldom used character saving this file to disk then encrypting.

after decryption I am replacing the characters with \r\n and \n respectively.

Perhaps not the best solution but it is working.
John Vorwald
Ranch Hand

Joined: Sep 26, 2010
Posts: 139
Hope this helps.
I changed the code only slightly, just to extract the decrypt file name.
I added a test program, and the results indicate that both \r and \n were written to and read from the encrypted file.
Suspect that you were using readline to read the decrypted file, and readline does not read the end of line characters. I used read instead, and the end of line characters are in the decryped file.


The output from the test is shown here, and contains both \n\r.


Decrypt: "Line 1: Have a happy day.

" has \n true has \r true
Decrypt: "Line 2: It was snowing this afternoon.

" has \n true has \r true
Decrypt: "Line 3: Will it rain tommorrow.

" has \n true has \r true
Decrypt: "Line 4: It's getting late.

" has \n true has \r true
Decrypt: "" has \n false has \r false

P White
Greenhorn

Joined: Dec 28, 2011
Posts: 10
John,

Thank you for this information. It will come in very useful for next time.

I very much appreciate your time in helping me.

Thank you

Paul
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File encryption / decryption retaining line feeds