Solved

Split wav file Java

Posted on 2009-03-31
3
1,043 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

636 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