Au Yiu Fai
Posts: 2
Nickname: kenneth
Registered: Apr, 2003
|
|
Re: download image by java program?
|
Posted: Apr 8, 2003 11:00 AM
|
|
Now i modify my program to this:
import java.net.*; import java.io.*; import java.util.regex.*; import java.util.*; import java.awt.*; import java.awt.event.*; import java.awt.Image;
public class readHSBC { public static void main(String [] args) throws Exception {
String website = "http://chart.yahoo.com/c/1y/0/0005.hk.gif"; String c="c"; String line;
try { URL DocURL = new URL(website); DataInputStream data = new DataInputStream(DocURL.openStream()); FileOutputStream fout = new FileOutputStream(c); while ((line = data.readLine()) != null) { WriteToFile(fout, line); } fout.close(); data.close(); } catch (MalformedURLException me) { System.out.println("MalformedURLException:" + me); } catch (IOException ioe) { System.out.println("IOException: " + ioe); } }
public static void WriteToFile(FileOutputStream fout, String line) throws IOException { for (int i = 0; i < line.length(); i++) fout.write(line.charAt(i)); fout.write('\n');
}
}
i can create a gif file with this program but the result is not good. Any one can help me?
|
|