FileSteamReadWrite1
(Also review this file : IO_Show_bytes_ByteStream.htm )
OutPut-text

Code snippet:

Complete Code :

/**
*
*/
import java.io.*;
import java.net.URI;
/**
* @author Manas9
*
*/
public class ClassTemplate1 {

/**
*
*/
public ClassTemplate1() {
// TODO Auto-generated constructor stub

}

/**
* @param args
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
//C:\Eclipse_workspace\javaCore\Template1\Project1
File localFile = new File("C:" + File.separator + "Eclipse_workspace" +
File.separator + "javaCore"+File.separator +"Template1"+
File.separator +"Project1"+ File.separator ,"test.txt");
System.out.println("localFile canRead(): "+ localFile.canRead());
System.out.println("Name :"+ localFile.getName());
System.out.println("C:"+ localFile.getPath());
FileInputStream inPut = null;FileOutputStream outPut = null;
int n1= 0; int strLength;
try {
inPut = new FileInputStream("test.txt");
System.out.println("Read file contents:");
outPut = new FileOutputStream("output.txt");
System.out.println("write file contents:");
while ((strLength = inPut.read()) != -1) {
outPut.write(strLength);
n1= strLength;
}
}finally {
if (inPut != null) { inPut.close(); }
if (outPut != null) { outPut.close(); }
}
System.out.println("File length" +" " + localFile.length());
System.out.println("Bytes" +" " + n1);
}
}
 

Runtime View