Разделите аудиофайл mp3 размером 5 МБ на 5 частей по 1 МБ каждый и сохраните его в формате mp3, и контент должен воспроизводиться. - PullRequest
0 голосов
/ 09 февраля 2019

Я нашел эту логику и попробовал, но это разделить файлы и магазины в формате txt

public static void splitFile(File f) throws IOException {
    int partCounter = 1;//I like to name parts from 001, 002, 003, ...
                        //you can change it to 0 if you want 000, 001, ...

    int sizeOfFiles = 1024 * 1024;// 1MB
    byte[] buffer = new byte[sizeOfFiles];

    try (BufferedInputStream bis = new BufferedInputStream(
            new FileInputStream(f))) {//try-with-resources to ensure closing stream
        String name = f.getName();

        int tmp = 0;
        while ((tmp = bis.read(buffer)) > 0) {
            //write each chunk of data into separate file with different number in name
            File newFile = new File(f.getParent(), name + "."
                    + String.format("%03d", partCounter++));
            try (FileOutputStream out = new FileOutputStream(newFile)) {
                out.write(buffer, 0, tmp);//tmp is chunk size
            }
        }
    }
}

public static void main(String[] args) throws IOException {
    splitFile(new File("D:\\destination\\myFile.mp3"));
}

После разделения мне нужно знать, как преобразовать или сохранить этот файл в mp3 или любой аудиоформат?

...