InputOutputDemoString.java Source code

Java tutorial

Introduction

Here is the source code for InputOutputDemoString.java

Source

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;

public class InputOutputDemoString {

    public static void main(String[] a) throws Exception {

        //Read from a String s as if it were a text file:
        Reader r = new StringReader("abc");
        System.out.println("abc: " + (char) r.read() + (char) r.read() + (char) r.read());
        //Write to a StringBuffer as if it were a text file:
        Writer sw = new StringWriter();
        sw.write('d');
        sw.write('e');
        sw.write('f');
        System.out.println(sw.toString());
    }
}