CS411X - Advanced Java Lecture 1

ContentsIndexNext

Lecture Topics:


 
 
 
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

Keyboard

----------SIS-----------

Your program

----------SOS----------

Display

Input file

----------FIS-----------

Your program

----------FOS----------

Output file

 
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

473

887

210s

 
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;
           
 

Sample Quiz

 
1. System.out is:
 
     a. A printout of system file
 
     b. Standard output stream
 
     c. File output stream
 
     d. A subclass of FileOutputStream
 
 
 
 

homeContentsIndexNext

UBLOGOLast Update: 04/09/97
Copyright © 1997- Douglas Lyon
Lyon@cse.bridgeport.edu