Split and join back a binary file in java

后端 未结 7 839
闹比i
闹比i 2020-12-13 10:45

I am trying to divide a binary file (like video/audio/image) into chunks of 100kb each and then join those chunks back to get back the original file. My code seems to be wor

7条回答
  •  不知归路
    2020-12-13 11:17

    It takes split file name & destination file size(in byte) form user and split it into subfiles its working for all type of files like(.bin,.jpg,.rar)

    import java.io.*;
    class split{
    public static void main(String args[])throws IOException {
    String a;
    int b;
    long len;
    Console con=System.console();
    System.out.println("Enter File Name: ");
    File f=new File(con.readLine());
    System.out.println("Enter Destination File Size: ");  
    b=Integer.parseInt(con.readLine());
    FileInputStream fis=new FileInputStream(f);
    len=f.length();
    int c=(int)len/b;
    if(((int)len%b)!=0)
    c++;
    for(int i=0;i

    and another program will merge all the split files.It take only split file name and merge all the files.

    import java.io.*;
    class merge{
    static int i;
    public static void main(String args[])throws IOException{
    String a;
    int b;
    long len;
    Console con=System.console();
    System.out.println("Enter File to be retrived: ");
    File f=new File(con.readLine());
    FileOutputStream fos=new FileOutputStream(f,true);
    try {
    File f1=new File(i+""+"."+f);
    while((f1.exists())!=false) {
    int ch;
    FileInputStream fis=new FileInputStream(i+""+"."+f);
    i++;
    while((ch=fis.read())!=-1){
    fos.write(ch);  }}}
    catch(FileNotFoundException e1){} }}
    

提交回复
热议问题