Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
A file chooser is a component that provides access to the file system. You can add a file
chooser directly to your application or set it up to open as a dialog. The JFileChooser class
provides three methods that display file chooser dialogs: showOpenDialog with an "Open"
approve button, showSaveDialog with a "Save" approve button, and showDialog with a
user-defined approve button. Keep in mind that a JFileChooser object only allows you to
retrieve the user-selected pathname; any opening, saving, or other file manipulating must
be implemented by you. Another way to present a file chooser is to add an instance of
JFileChooser to a container.
JFileChooser()
JFileChooser(File currentDirectory)
JFileChooser(FileSystemView fsv)
JFileChooser(String currentDirectoryPath)
Constructs a JFileChooser using the given current directory path and FileSystemView
Java uses a hierarchy of classes to deal with different types of data. The InputStream and
OutputStream are abstract classes that use low-level I/O streams to read bytes from or
send them to I/O devices such as files, network sockets, and pipes.
1 Mrs.Anamika Raj,Lecturer,KKU
COMPUTER PROGRAMMING-2 JAVA
Low-level streams. An input or output stream that connects directly to a data source, such
as a file or socket.
High-level streams. An input or output stream that reads or writes to another input or
output stream.
FileInputStream and FileOutputStream. For writing and reading binary data from a file.
PipedInputStream and PipedOutputStream. For writing and reading data between two
threads.
Object IO
Object-
ObjectOutputStream
2 Mrs.Anamika Raj,Lecturer,KKU
COMPUTER PROGRAMMING-2 JAVA
Is a high-level class that can be used to send primitive values and "serializable"
objects to a stream. All that is needed for an object to be serializable, is that its class
must implement the Serializable interface. For example, if a Customer class is to be
serializable, its header may be coded
Many packaged classes are serializable including all wrapper classes, String and
Stringbuffer classes, Vector and Array classes, and the collection classes. In other words, an
entire collection, such as a SortedMap, can be stored as an object on disk!
Has overloaded constructors but the most useful "chains" to an object that descends
from the OutputStream class (such as a FileOutputStream object). For example, if fd
is the reference of a File object
Method Usage
writeBoolean() Writes a specified boolean value to the stream
writeByte() Writes a specified byte value to the stream
writeChar() Writes a specified char value to the stream
writeDouble() Writes a specified double value to the stream
writeFloat() Writes a specified float value to the stream
writeInt() Writes a specified int value to the stream
writeLong() Writes a specified long value to the stream
writeObject() Writes a specified serializable object to the stream
writeShort() Writes a specified short value to the stream
Writes a specified String to the stream according to the
writeUTF()
UTF standard
3 Mrs.Anamika Raj,Lecturer,KKU