files and i o n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
CSC1351 PowerPoint Presentation
Download Presentation
CSC1351

Loading in 2 Seconds...

play fullscreen
1 / 6

CSC1351 - PowerPoint PPT Presentation


  • 82 Views
  • Uploaded on

Files and I/O. CSC1351. Input. Reader - based on chars BufferedReader - wraps a reader String readLine() FileReader - opens files for reading StringReader - reads from a string InputStreamReader - wraps in input stream InputStream - based on bytes

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

CSC1351


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
input
Input
  • Reader - based on chars
    • BufferedReader - wraps a reader
      • String readLine()
    • FileReader - opens files for reading
    • StringReader - reads from a string
    • InputStreamReader - wraps in input stream
  • InputStream - based on bytes
    • BufferedInputStream - wraps an input stream
    • FileInputStream - opens files for reading
    • ObjectInputStream - read whole objects
    • ByteArrayInputStream - read from a byte array
output
Output
  • Writer
    • FileWriter - create / append to files
    • StringWriter - create strings
    • BufferedWriter - wrapper for a writer
    • PrintWriter - provides println()
    • OutputStreamWriter - write to a stream
  • OutputStream
    • FileOutputStream - create / append to files
    • ByteArrayOutputStream - create a byte array
    • BufferedOutputStream - wraper for a stream
    • PrintStream - provides println()
    • ObjectOutputStream - write whole objects
making your own
Making your own
  • javap java.io.Reader | grep abstract
    • int read(char[], int, int);
    • void close();
  • javap java.io.InputStream | grep abstract
    • int read();
  • javap java.io.Writer | grep abstract
    • void write(char[], int, int)
    • void flush();
    • void close();
  • javap javai.io.OutputStream | grep abstract
    • void write(int);
nulloutputstream

import java.io.OutputStream;

import java.io.PrintStream;

public class NullOutputStream extends OutputStream {

public void write(int a) {}

public static void main(String[] args) {

NullOutputStream nout = new NullOutputStream();

PrintStream ps = new PrintStream(nout);

ps.println("Hello, world.");

}

}

NullOutputStream
capoutputstream

import java.io.OutputStream;

import java.io.PrintStream;

public class CapOutputStream extends OutputStream {

public void write(int a) {

char c = (char)a;

System.out.write(Character.toUpperCase(c));

}

public static void main(String[] args) {

CapOutputStream cout = new CapOutputStream();

PrintStream ps = new PrintStream(cout);

ps.println("Hello, world.");

}

}

CapOutputStream