View Single Post
  #1 (permalink)  
Old 08-07-2007, 05:43 PM
one198 one198 is offline
Member
 
Join Date: Aug 2007
Posts: 15
one198 is on a distinguished road
Problem in my coding
Hi guys

Iam developing software like offline web browser,but I am at initial stages.
my idea is geting content of web page and save it to text file.I wrote down my coding below ,but it's gave me error

Error is "can not resolve method 'write(java.lang.StringBuffer)' "

pls help

Thank you

import java.net.*;
import java.io.*;
import java.nio.channels.FileChannel;
import java.lang.String;
import java.nio.ByteBuffer;

public class Test {


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

File aFile = new File("D:\\Java\\First.text");
setcontents(aFile,getcontent());
}

static public StringBuffer getcontent()
{
StringBuffer contents = new StringBuffer();
String text[];
try{
URL yahoo = new URL("http://www.yahoo.com");
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));

String line;
while (( line = in.readLine()) != null)
{
contents.append(line);
contents.append(System.getProperty("line.separator "));

}
}
catch(IOException e){
e.printStackTrace();
}
return contents;
}


static public void setcontents(File afile,StringBuffer acontents)
{
Writer output=null;
try{
output=new BufferedWriter(new FileWriter(afile));
output.write(acontents);
}
catch(IOException e){
e.printStackTrace();
}
}


}
Reply With Quote
Sponsored Links