Solved

Split wav file Java

Posted on 2009-03-31
3
1,017 Views
Last Modified: 2012-05-06
I want to split a wave format file into multiple small file. For e.g. If we have a 1 big wave file then i want to break that file in small 10 wave files. Is it possible in java and If YES then how?
Thanks in Advance
0
Comment
Question by:parveendalal
3 Comments
 
LVL 12

Accepted Solution

by:
basav_com earned 500 total points
ID: 24031981
0
 
LVL 9

Expert Comment

by:brunoguimaraes
ID: 24032302
See code below, taken from http://www.coderanch.com/t/436301/Java-General-intermediate/java/split-file
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import javax.swing.JOptionPane;
 
 
public class SplitFile {
    int FRG_FSIZE=0;
    
    public File[] splitFile(File source,int noFile,int lsize)
    {
        FRG_FSIZE = 1024*5;
        File[] fileFragments = new File[noFile];
        String[] frgfName = new String[noFile];
            try{    
                String sourceFName = source.getName();
                long sourceFSize = source.length();
                FileInputStream fis = new FileInputStream(source);
 
                String Fileinfo = new String(sourceFName + "," + String.valueOf(sourceFSize));
                System.out.println(noFile);
                if (lsize != 0) {
                    noFile--;
                }
                System.out.println(noFile);
                sourceFName = sourceFName.substring(0, sourceFName.lastIndexOf("."));
                int j=0;
                for (int i = 1; i <= noFile; i++) {
                    frgfName[i-1] ="temp\\"+sourceFName + String.valueOf(i)+".splt";
                    fileFragments[i-1] = new File(frgfName[i-1]);
                   
                    FileOutputStream fos = new FileOutputStream(fileFragments[i - 1]);
                    byte[] data = new byte[FRG_FSIZE];
                    int count = fis.read(data);
                    fos.write(data);
                    fos.close();
                    String frgFileInfo = new String(frgfName[i-1] + "," + String.valueOf(FRG_FSIZE));
                }
                if (lsize != 0) {                    
                    System.out.println(noFile);
                    frgfName[noFile] ="temp\\"+sourceFName + String.valueOf(noFile+1)+".splt";
                    fileFragments[noFile] = new File(frgfName[noFile]);
                    FileOutputStream fos = new FileOutputStream(fileFragments[noFile]);
                    byte[] data = new byte[lsize];
                    int count = fis.read(data);
                    fos.write(data);
                    fos.close();
                    String frgFileInfo = new String(frgfName[noFile] + "," + String.valueOf(lsize));
                }
 
               } catch (Exception e) {
                      
                   System.out.println("Error in Splitting"+e);
                    JOptionPane.showMessageDialog(null, "Error in Splitting File \n"+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                     return null;
               }
        return fileFragments;
  }
  
  public static void main(String ar[])
  {
  	SplitFile sf=new SplitFile();
	sf.splitFile(new File("Placement.doc"),5,1024);
  }
 
 
}

Open in new window

0
 
LVL 17

Expert Comment

by:Thomas4019
ID: 24033686
brunoguimaraes, your answer may split the file but it produces a number of completely useless, unplayable files. A much better solution would to be use part of the Java Media Framework (JMF) as basav_com has suggested.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping2 challenge 13 90
MySqlDump not dumping triggers 1 30
Configure a Bean in an XML file 4 31
hibernate example using maven 12 41
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question