import java.io.*;
class TestByteStreams{
public static void main(String args[]) throws IOException
{
File f1=new File("C:\\Program Files\\Java\\jdk1.5.0_14\\test\\AJP","BoxArray.java");
System.out.println("Path seperator=" + f1.pathSeparator);
System.out.println("seperator=" + f1.separator);
FileInputStream fInputStream = new FileInputStream(f1);
BufferedInputStream bInputStream = new BufferedInputStream(fInputStream);
byte byteInputArray [] = new byte[500];
FileOutputStream fOutputStream = new FileOutputStream (f1 + "_copy2.java");
BufferedOutputStream bOutputStream = new BufferedOutputStream(fOutputStream,1024);
int count;
while ((count = bInputStream.read(byteInputArray,0,500))>0)
{
//BufferedOutputStream data is written to file or out when the buffer size = 1024 specified in the bufferedoutputstream is reached.
bOutputStream.write(byteInputArray,0,count);
}
//Once reading is complete and byteInputArray filled size is less than 1024 buffered output stream size,
//the output will not be written unless flushed exclusively
bOutputStream.flush();
fInputStream.close();
fOutputStream.close();
/*ByteArrayOutputStream bo = new ByteArrayOutputStream();
String s1 = "Twinkle twinkle litte star";
String s2 = "How I wonder what you are";
byte b1[] = s1.getBytes();
byte b2[] = s2.getBytes();
bo.write(b1);
bo.write(b2);
bo.close();
byte b3[] = bo.toByteArray();
ByteArrayInputStream bi = new ByteArrayInputStream(b3);
int size = bi.available();
for (int i=0; i
System.out.print((char) bi.read());
}
System.out.println();*/
}
}
No comments:
Post a Comment