Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Merge and split file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Merge and split file" Watch "Merge and split file" New topic
Author

Merge and split file

ba thong
Greenhorn

Joined: Mar 08, 2009
Posts: 6
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
Bartender

Joined: Oct 14, 2005
Posts: 18121
    
    8

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

Joined: Mar 08, 2009
Posts: 6
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
Bartender

Joined: Oct 14, 2005
Posts: 18121
    
    8

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

Joined: Mar 08, 2009
Posts: 6
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Merge and split file
 
Similar Threads
SequenceInputStream performance
Doubt in Renaming File
File class and the length method
Problem in setBinaryStream when using SequenceInputStream
File Not Found Exception when uploading