About Sound File
sun.audio.NativeAudioStream class
throw an InvalidAudioFormatException to convert .wav and .aiff file
to .au audio file.
.au = sun audio file refers to 8-bit, 8,000 Hz, ulaw ( compounded
format) encoded audio file.
About Project
Stream
FileDialog
the java.awt contains a specialized
dialog class, it inherits form Dialog class.
Constructors
FlieDialog ( Frame, String )
import java.io.FileInputStream;
to perform file processing in java, the package java.io must be
imported.
Example
static public File get_dir(Frame f) { FileDialog dialog = new FileDialog(f, "select file"); dialog.show(); String file_name = dialog.getFile(); String dir_name = dialog.getDirectory(); System.out.println("dir:" + dir_name + "file:"+file_name); dialog.dispose(); return new File(dir_name); } FlieDialog fd = new FileDialog ( this, "Open a File" ); //Open a File is the title of the dialog box The static constants FileDialog.SAVE and FileDialog.LOAD specify the type of file dialog to create. int = FileDialog.SAVE int = FileDialog.LOAD java.io creating file stream for input and output, InputStream and OutputStream created use and detect the end of filter input stream. The stream associated with stream object ( system.in/system.out/system.err ) as a pipe A pipe == A uninterpreted stream of bytes used to communicate between: Program #1 ------------------ Program #2 Program ---------------------- file Program --------------------- Device
|
----------SIS----------- |
|
----------SOS---------- |
|
|
|
|
|
|
|
----------FIS----------- |
|
----------FOS---------- |
|
FileInputStream New Class FileInputStream inputfile = new FileInputStream ( "in.dat" ); in.dat is file specification Example Filespec ( "Pub/i/wow/in.dat" ); Example static public File get_file(Frame f) { FileDialog dialog = new FileDialog(f, "select file"); dialog.show(); String file_name = dialog.getFile(); String dir_name = dialog.getDirectory(); System.out.println("dir:" + dir_name + "file:"+file_name); dialog.dispose(); return new File(file_name); } FileInputStream input_stream = new FileInputStream(input_name); StreamTokenizer tokens = new StreamTokenizer(input_stream); FileOutputStream output_stream = new FileOutputStream(output_name); PrintStream output = new PrintStream(output_stream); StreamTokenizer To read number and string, convert a FileInputStream instance into a StreamTokenizer instance. static public void list_filtered_href_file(String file) { System.out.println("processing:\t" + file); try { FileInputStream input_file = new FileInputStream(file); StreamTokenizer tokens = new StreamTokenizer(input_file); int next = 0; tokens.resetSyntax(); tokens.wordChars(0,255); tokens.quoteChar('"'); while ((next = tokens.nextToken()) != tokens.TT_EOF) { switch (next) { case '"': System.out.print('"'); StringTokenizer st = new StringTokenizer(tokens.sval," "); while (st.hasMoreTokens()) { System.out.print(st.nextToken()); if (st.countTokens() > 1) {System.out.print("%20");} } System.out.print('"'); break; case tokens.TT_WORD: System.out.print(tokens.sval+" "); break; case tokens.TT_NUMBER: System.out.print(tokens.nval+" "); break; case tokens.TT_EOL: System.out.println(); break; } } System.out.println(); input_file.close(); } catch (Exception exe) {System.out.println("list_filtered_href_file:er!");} }
in file |
The first time token.nextToken( ); is called the first token is loaded. Numbers a loaded into token.aval, a double. Example while ((next = tokens.nextToken()) != tokens.TT_EOF) { switch (next) { case '"': System.out.print('"'); StringTokenizer st = new StringTokenizer(tokens.sval," "); while (st.hasMoreTokens()) { System.out.print(st.nextToken()); if (st.countTokens() > 1) {System.out.print("%20");} } System.out.print('"'); break;
1. System.out is: a. A printout of system file b. Standard output stream c. File output stream d. A subclass of FileOutputStream
Last
Update: 04/09/97
Copyright © 1997- Douglas Lyon
Lyon@cse.bridgeport.edu