I need help with a IO java code, I am trying to save java console output [from URL class] to a file in local machine, I am able to get the output need help in saving that file to the local machine
to get the output I did this coding
import java.net.*;
import java.io.*;
public class URLConnectionReader {
public static void main(String[] args) throws Exception {
URL oracle = new URL("http://www.yahoo.com/");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
Note : I have a another code, in which I can save the output to a file, but unable to co-relate both of the both, I have tried extending, but no progress , here is that class
import java.io.*;
class FileWrite {
public static void main(String args[]) {
try{
// Create file
FileWriter fstream = new FileWriter("out.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write("Hello Java");
//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}