Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Merge and split file

 
ba thong
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have 2 file, a file is text, a file is encrypted, i merge them by

I write a method ReadFile and return String, but part file encrypted is changed.


This is file merge

This is result of method ReadFile

How i can split them that don't throught String??? Thanks a lot of
 
Paul Clapham
Sheriff
Pie
Posts: 20958
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you are reading bytes which don't represent text -- like those encrypted bytes you have at the back end of that file there -- don't use a Reader to read them. Use an InputStream instead, exactly like you did in the first program.
 
ba thong
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you.
My goal is split file, i can't write method ReadFile(String filename) that return byte[] (can you help me ???), then how i can split file form that array byte ??
 
Paul Clapham
Sheriff
Pie
Posts: 20958
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see why you need a ReadFile method which returns an array of bytes. If I understand it correctly, your mushed-together file consists of one set of data, then an "@", then another set of data. So read bytes until you hit the @, and write all of those bytes (except the @) into the first file. Then copy the rest of the bytes into the second file. Sort of like your first program.

By the way, why did you decide to do this? Mashing two kinds of data into a single file is rarely a good idea. I wouldn't do that if I had to store the text and the encrypted data, I would just store them in two separate files. And not only because it's hard to write a program to split the two, also because you now need a rule which says you can't have the "@" character in the text half of the file.
 
ba thong
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you a lot of
I merge file because i 'm doing about digital signature. i need encrypt file root document and file digital signature then i ecrypt them by public key of receiver. Do you have idea for me ??? Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic