Java – split the file into four parts

I want to divide a file (suppose an MP3) into four parts I tried this code But only file1 Mp3 works normally I can't play with others What did I do wrong here?

try     {

        FileInputStream in=new FileInputStream(f);
        long i=f.length();
        long j=i/4;

        FileOutputStream f0=new FileOutputStream("File1.mp3");
        FileOutputStream f1=new FileOutputStream("File2.mp3");
        FileOutputStream f2=new FileOutputStream("File3.mp3");
        FileOutputStream f3=new FileOutputStream("File4.mp3");

        for(long k=0;k<j;k++){
            f0.write(in.read());
        }
        f0.close();
        for(long l=0;l<j;L++){
            f1.write(in.read());
        }
        f1.close();
        for(long m=0;m<j;m++){
            f2.write(in.read());  
        }
        f2.close();
        for(long n=0;n<j;n++){
            f3.write(in.read());
        }
        f3.close();

        in.close();
    }
    catch (IOException e)
    {

    }

Solution

You cannot split structured files like this: MP3 file has a header at the beginning of the file describes the contents of the rest of the file When splitting a file, you only get the title in the first part

As for cutting unstructured files, such as text, your code should be much better, as long as you don't mind dividing your sentence into the middle of a word

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>