Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I Read in wav files in Java? 1

Status
Not open for further replies.

JasmineT

Programmer
Apr 16, 2003
2
JM
i have a file in the directory that is in wav format and i want to read it into my program. what file stream do i use?

i have tried this code so far : 2 classes.

import java.io.*;
import java.util.*;




class Tester implements Serializable{

Object myFile;

public Tester getTest()
{

return (Tester)myFile;

}

public void setTest(Object myFile)
{

this.myFile = myFile;

}


}



and the one that reads the object


import java.io.*;
import java.util.*;


public class ObjectFromDisk{

public static void main(String []arg)
{
try{

FileInputStream fi = new FileInputStream("connect.wav");
ObjectInputStream oi = new ObjectInputStream(fi);

Tester tes = (Tester) oi.readObject();

System.out.println("I hope this works");
oi.close();

}catch(Exception e){System.out.println("Error -- " + e.toString());
}

}

}


i keep getting this error however :
java.io.StreamCorruptedException : invalid stream header.


 
Hello All,

I have two clases one class1 which extends JTextPane and another one class2 which extends JComboBox.
I created class2 object in class1 and added class2 object to class1.(i.e i added JComboBox to JTextPane).After adding component in class1, i would like to put focus to that component.How can it possible?
 
You have to use the requestFocus() method. However, if you want the combo to get the initial focus when starting your application, you have to call the method after blablabla... (no time to explain for the moment) e.g. :
Code:
    frame.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent evt) {
            System.exit(0);
          }
          public void windowOpened(WindowEvent evt) {
            combo.requestFocus();
          }
      });
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top