background preloader

FileHandling

Facebook Twitter

ServletOutputStream (Java EE 6 ) Java.lang.Object java.io.OutputStream javax.servlet.ServletOutputStream All Implemented Interfaces:

ServletOutputStream (Java EE 6 )

Files (Java Platform SE 7 ) Walks a file tree.

Files (Java Platform SE 7 )

This method walks a file tree rooted at a given starting file. The file tree traversal is depth-first with the given FileVisitor invoked for each file encountered. File tree traversal completes when all accessible files in the tree have been visited, or a visit method returns a result of TERMINATE. Where a visit method terminates due an IOException, an uncaught error, or runtime exception, then the traversal is terminated and the error or exception is propagated to the caller of this method. For each file encountered this method attempts to read its BasicFileAttributes. Where the file is a directory, and the directory could not be opened, then the visitFileFailed method is invoked with the I/O exception, after which, the file tree walk continues, by default, at the next sibling of the directory.

Where the directory is opened successfully, then the entries in the directory, and their descendants are visited. File Handling using Input-Output Streams in Java. An I/O Stream represents an input source or an output destination.

File Handling using Input-Output Streams in Java

A stream can represent many different kinds of sources and destinations, disk files, devices, other programs, etc. Streams support many different kinds of data simple bytes, primitive data types, localized characters, and objects. Some streams simply pass on data; others manipulate and transform the data in useful ways. Data is transferred to devices by streams. Reading/Writing to Stream A stream is a sequence of data. A program uses an output stream to write data to a destination: Byte StreamsCharacter StreamsBuffered Streams JAVA distinguishes between 2 types of streams: Text – streams, containing ‘characters‘ Binary Streams, containing 8 – bit information 1. Programs use byte streams to perform input and output of 8-bit bytes. InputStreamOutputStream (both are abstract) There are many byte stream classes for example FileInputStream and FileOutputStream.

Important Methods 2. Reader ClassWriter Class (both are abstract) File download servlet (Servlets forum at JavaRanch)