Results 1 to 13 of 13
Thread: Merge file
- 06-14-2011, 08:11 AM #1
Merge file
I write a small application to merge file, current it merge text file, audio file but not work with video file. I don't know why. this's code:
PHP Code:public static void main(String[] args) throws IOException { // TODO Auto-generated method stub JFileChooser F = new JFileChooser(); String[] Path = new String[2]; for(int i=0;i<=1;i++){ int t = F.showOpenDialog(null); if(t==F.APPROVE_OPTION){ File F1 = F.getSelectedFile(); Path[i] = F1.getPath(); } } if(F.showSaveDialog(null)==JFileChooser.APPROVE_OPTION){ FileOutputStream out = new FileOutputStream(F.getSelectedFile()); for(int i=0; i<=1;i++){ FileInputStream F1 = new FileInputStream(Path[i]); int n = F1.available(); while(n>0){ byte[] B = new byte[n]; int k = F1.read(B); if(k==-1) break; out.write(B); } F1.close(); } out.close(); } JOptionPane.showMessageDialog(null, "Merge Successful...!"); }
- 06-14-2011, 01:27 PM #2
What do you mean by merge? Do you mean: Copy the contents of one file after the contents of another file so that the new file has the contents of one file in front followed by the data from the second file.
If their is a program that reads a specific type of file and processes it, like a video that is displayed, why do you think that program will understand finding more data following the contents of what it thinks is a single file?
- 06-14-2011, 02:58 PM #3
I think copy the contents of one file after the contents of another file so that the new file. I don't understand you. Can you explain to me?
- 06-14-2011, 03:08 PM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
It's possible that a video file will have a header at the start that gives information about the video, such as the length, or number of frames, etc. Appending another file on the end wouldn't change this header information, so the merged section might not be recognised (also, the merged file might have its own header information).
I'm not a video guru, so I don't know, but it strikes me as likely. I suggest you find out how commercial video editing applications merge videos.
- 06-14-2011, 03:19 PM #5
Thanhks to dlorde, because i want to try code myself.
- 06-14-2011, 04:33 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Quoting from the API:Java Code:int n = F1.available();
Bolding mine.Returns an estimate of the number of remaining bytes that can be read...
It would be more reliable for you to read in a loop storing into a byte buffer of some size (8k is the norm).
That said, as already mentioned there may well be header information in a video file. To be honest, I'm surprised it worked for some audio files (unless they're wav).
- 06-14-2011, 05:49 PM #7
- 06-14-2011, 05:55 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Probably, but then it can probably read in the whole of the small file quite easily.
The usual way is something along the lines of:
That reads from in, and writes to out.Java Code:byte[] buffer = new byte[about 8k]; while ((n = in.read(buffer)) > -1) { out.write(buffer, n); }
You'll have to check the API for exact details as I've done this off the top of my head, which invariably means I've got something wrong.
- 06-14-2011, 06:06 PM #9
I try, thanks to Tolls
- 06-14-2011, 06:13 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Note, this isn't going to help you at all if the file format involves headers...which is likely.
- 06-14-2011, 06:19 PM #11
I know, if i do with file format involves headers as video file,..what can i do?
- 06-14-2011, 06:21 PM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Leanr the file formats and see if you can do stuff involving merging the file data and relevant parts of the header.
But that involves knowing the stuff you're working with.
- 06-14-2011, 06:24 PM #13
Similar Threads
-
Merge Two Xml files ????
By alwz_nikhil in forum XMLReplies: 5Last Post: 01-18-2011, 09:18 AM -
Merge XML using XSL
By palanikumark in forum XMLReplies: 1Last Post: 08-16-2008, 12:14 AM -
How do merge two xml files into one xml?
By veera in forum XMLReplies: 1Last Post: 03-27-2008, 05:06 PM -
Merge 2 button become one
By banie in forum AWT / SwingReplies: 1Last Post: 02-17-2008, 05:26 PM -
Merge Sort Help
By Hollywood in forum New To JavaReplies: 5Last Post: 01-30-2008, 03:26 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks