- Arulkumar V
Assistant Professor, SECE
Java Stream & IO
What is Stream in java
12/19/20172
 A stream can be defined as a sequence of data.
There are two kinds of Streams −

InPutStream − The InputStream is used to read
data from a source.
 OutPutStream − The OutputStream is used for
writing data to a destination.
12/19/20173
Example
import java.io.*;
public class CopyFile {
public static void main(String args[]) throws IOException {
FileInputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream("input.txt");
out = new FileOutputStream("output.txt");
int c;
while ((c = in.read()) != -1)
{
out.write(c); } }
finally {
if (in != null)
{ in.close(); } if (out != null) { out.close(); } } } }
Reading and Writing Files
12/19/20174
The java.lang.String class
implements Serializable, Comparable and CharSequence
interfaces.
12/19/20175
String methods
12/19/20176
 Java String class provides a lot of
methods to perform operations on string
such as
 compare(), concat(), equals(), split(),
length(), replace(), compareTo(), intern(),
substring() etc.

String Example
12/19/20177
public class StringExample{
public static void main(String args[]){
String s1="java";//creating string by java string literal
char ch[]={'s','t','r','i','n','g','s'};
String s2=new String(ch);//converting char array to string
String s3=new String("example");//creating java string by
new keyword
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
}}
String methods ex
12/19/20178
public class CharAtExample{
public static void main(String args[]){
String name="javatpoint";
char ch=name.charAt(4);//returns the char value at the 4th index
System.out.println(ch);
}}
public class CharAtExample{
public static void main(String args[]){
String name="javatpoint";
char ch=name.charAt(10);//returns the char value at the 10th
index
System.out.println(ch);
}}
12/19/20179
12/19/201710
Thank You

Streams&io

  • 1.
    - Arulkumar V AssistantProfessor, SECE Java Stream & IO
  • 2.
    What is Streamin java 12/19/20172  A stream can be defined as a sequence of data. There are two kinds of Streams −  InPutStream − The InputStream is used to read data from a source.  OutPutStream − The OutputStream is used for writing data to a destination.
  • 3.
    12/19/20173 Example import java.io.*; public classCopyFile { public static void main(String args[]) throws IOException { FileInputStream in = null; FileOutputStream out = null; try { in = new FileInputStream("input.txt"); out = new FileOutputStream("output.txt"); int c; while ((c = in.read()) != -1) { out.write(c); } } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } } }
  • 4.
    Reading and WritingFiles 12/19/20174
  • 5.
    The java.lang.String class implementsSerializable, Comparable and CharSequence interfaces. 12/19/20175
  • 6.
    String methods 12/19/20176  JavaString class provides a lot of methods to perform operations on string such as  compare(), concat(), equals(), split(), length(), replace(), compareTo(), intern(), substring() etc. 
  • 7.
    String Example 12/19/20177 public classStringExample{ public static void main(String args[]){ String s1="java";//creating string by java string literal char ch[]={'s','t','r','i','n','g','s'}; String s2=new String(ch);//converting char array to string String s3=new String("example");//creating java string by new keyword System.out.println(s1); System.out.println(s2); System.out.println(s3); }}
  • 8.
    String methods ex 12/19/20178 publicclass CharAtExample{ public static void main(String args[]){ String name="javatpoint"; char ch=name.charAt(4);//returns the char value at the 4th index System.out.println(ch); }} public class CharAtExample{ public static void main(String args[]){ String name="javatpoint"; char ch=name.charAt(10);//returns the char value at the 10th index System.out.println(ch); }}
  • 9.
  • 10.