Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HELP! Writing and Reading .wav files. PLEASE!

 
Trelan Hylton
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not written a java code in several months but someone asked me a favour to write something that could read a text file for the name of a .wav or .vox file(these files are dynamically created by another program)then take these files in as objects and write them to a database. does anyone posses a sample code of something similar?
what kind of streams and input classes and interfaces are appropriate otherwise?
[ April 15, 2003: Message edited by: Trelan Hylton ]
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi JH,
You need to use the classes in the "java.io" package. The "*Reader" classes (i.e. classes whose names end with "Reader" like "FileReader") are intended for use with text files, whereas the "*Stream" classes are intended for binary files (i.e. non-text files).
If you want to store the ".wav" and/or ".vox" files in the database, then many databases allow this through the use of BLOBs (Binary Large OBject). As far as I know, each database vendor implements BLOBs differently. I suggest you check the documentation for your database and JDBC driver (assuming you want to use JDBC in order to store the ".wav", ".vox" files in the database).
There are several tutorials available on the Internet regarding I/O in java, including:
http://www-106.ibm.com/developerworks/edu/j-javaio-i.html
http://java.sun.com/docs/books/tutorial/essential/io/index.html
http://home.att.net/~baldwin.rg/Intermediate/Java060.htm
Hope this has helped you.
Good Luck,
Avi.
 
Trelan Hylton
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Zalewski
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because ObjectInputStream is for reading Java objects. A .wav file does not contain a Java object.
If your .wav file is large, it may not make sense to read the entire file into an object. But if the .wave file is small, you could do this:
(Off the top of my head. Might contain some errors)

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!