Solved

Split wav file Java

Posted on 2009-03-31
3
1,031 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet example 11 59
arguments to jar 5 40
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 79
Java syntax, or is it Selenium 6 43
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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.

696 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