Monday, June 1, 2015

DataInputStream

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

//The DataInputStreamDemo is used in the context of DataOutputStream and can be used to read primitives.

//InputStream in = DataInputStreamDemo(InputStream in);

// Methods with Description
// public final int read(byte[] r, int off, int len)throws IOException
// Public final int read(byte [] b)throws IOException
//public String readLine() throws IOException
// (a) public final Boolean readBooolean()throws IOException,
// (b) public final byte readByte()throws IOException,
// (c) public final short readShort()throws IOException
// (d) public final Int readInt()throws IOException

// NOTES:
// Firstly we have to create file input.txt and put some text in it which are
// both in capital and small letters.
//This example reads 5 lines given in a file input.txt and convert those lines into capital letters
//and finally copies them into another file output.txt.

public class DataInputStreamDemo {

public static void main(String[] args) throws IOException {

DataInputStream dIn = new DataInputStream(new FileInputStream("src/input.txt"));
DataOutputStream dOut = new DataOutputStream(new FileOutputStream("output.txt"));

String count;
while((count = dIn.readLine()) != null){
String uppercaseString = count.toUpperCase();
System.out.println(uppercaseString);      // print the content to the console screen
dOut.writeBytes(uppercaseString + "  ,");  // copying the text to the output.txt file
}
dIn.close();
dOut.close();
}
}


No comments:

Post a Comment