Hi,
Here is the sample code for reading a file block by block..
This piece of code extracts the full content(html) from a url and store a particular block(means from <form> to </form>) in
a file called somefilename.txt
import java.net.*;
import java.io.*;
import java.util.*;
class strbuf
{
public static void main(
String ar[])
throws IOException
{
URL url=new URL("http://www.usbullionexchange.com/pricesonline.cfm");
BufferedReader buf=new BufferedReader(new InputStreamReader(url.openStream()));
String in;
StringBuffer strbuffer=new StringBuffer();
String temp;
int startind=0;
int endind=0;
while ((in = buf.readLine()) != null)
{
if(in.length()>0)
strbuffer=strbuffer.append(" "+in);
}
temp=strbuffer.toString();
startind=temp.indexOf("<form ");>
endind=temp.indexOf("</form>");
byte[] b=temp.substring(startind,endind+7).getBytes();
try
{
FileOutputStream file=new FileOutputStream("somefilename.txt");
file.write(b);
}
catch(Exception e)
{
System.out.println("Error :"+e);
}
buf.close();
}
}
Hope this will help,
Best Regards,
Paramaguru.