Download java.util.Scanner

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
What is the difference between text files
and binary files?
How can you programmatically translate
binary data into text?
How can you programmatically translate
textual data into binary?
java.util.Scanner
«constructor»
+ Scanner( String )
+ Scanner( InputStream )
«query»
+ boolean nextBoolean( )
+ byte nextByte( )
+ double nextDouble( )
+ float nextFloat( )
+ int nextInt()
+ String nextLine( )
+ long nextLong( )
+ short nextShort( )
+ String next( )
«predicate»
+ boolean hasNext( )
+ boolean hasNextBoolean( )
+ boolean hasNextByte( )
+ boolean hasNextDouble( )
+ boolean hasNextFloat( )
+ boolean hasNextInt()
+ boolean hasNextLong( )
+ boolean hasNextShort( )
...
The Object of Data Abstraction
and Structure, David D. Riley
© Addison Wesley pub.
In addition to binary and text I/O streams, Java provides for at least three
other kinds of I/O:
Serialized Objects
via ObjectInputStream and ObjectOutputStream classes
Random Access to File Content
via RandomAccessFile class
Terminal-style I/O
via System.in and System.out objects
The Object of Data Abstraction
and Structure, David D. Riley
© Addison Wesley pub.
These classes permit I/O of whole objects.
Objects to be stored must implement java.io.Serializable.
Caution: Serialized objects pose a potential vulnerability.
java.io.ObjectOutputStream
«constructor»
+ ObjectOutputStream( OutputStream )
...
«output»
+ void writeObject( Object )
+ void flush()
+ void close()
...
java.io.ObjectInputStream
«constructor»
+ ObjectInputStream( InputStream )
...
«input»
+ Object readObject()
+ void close()
...
The Object of Data Abstraction
and Structure, David D. Riley
© Addison Wesley pub.
java.io.RandomAccessFile
- permits direct access to any byte of a file. «constructor»
- binary files
+ RandomAccessFile( String, String )
«input»
+ boolean readBoolean( )
+ byte readByte( )
+ double readDouble( )
+ char readChar( )
+ float readFloat( )
+ int readInt()
+ String readLine( )
+ long readLong( )
+ short readShort( )
...
«output»
+ void writeBoolean( boolean )
+ void writeByte( byte )
+ void writeDouble( double )
+ void writeChar( char )
+ void writeFloat( float )
+ void writeInt( int )
+ void writeLine( String )
+ void writeLong( long )
+ void writeShort( short )
...
«positioning»
+ long getFilePointer( )
+ void seek( long )
The Object of Data Abstraction
and Structure, David D. Riley
© Addison Wesley pub.
- interactive & blocking
- blocking
java.lang.System
+ static InputStream in
+ static PrintStream out
+ static PrintStream err
import java.util.Scanner;
public class Driver {
public Driver () {
String userInput;
Scanner inScan = new Scanner( System.in );
System.out.print("Type a token: ");
userInput = inScan.next();
System.out.println("Your token: " + userInput);
}
}
The Object of Data Abstraction
and Structure, David D. Riley
© Addison Wesley pub.
Related documents