Thursday, 31 January 2013

Input-stream to File Generation in Java

Input-stream to File Generation in Java

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Convert_InputStream_toFile
{
public static void main(String args[])
{
try
{
File f=new File("outFile.java");
InputStream inputStream= new FileInputStream("InputStreamToFile.java");
OutputStream out=new FileOutputStream(f);
byte buf[]=new byte[1024];
int len;
while((len=inputStream.read(buf))>0)
out.write(buf,0,len);
out.close();
inputStream.close();
}
catch (IOException e){}
}
}

No comments:

Post a Comment