The Artima Developer Community
Sponsored Link

Java Answers Forum
download image by java program?

1 reply on 1 page. Most recent reply: Apr 8, 2003 11:00 AM by Au Yiu Fai

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Au Yiu Fai

Posts: 2
Nickname: kenneth
Registered: Apr, 2003

download image by java program? Posted: Apr 8, 2003 10:39 AM
Reply to this message Reply
Advertisement
Hi,
i have a problem that want to downloan http://chart.yahoo.com/c/1y/0/0005.hk.gif to my computer by using a java program. This is my trial program.

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 readYahoo {
public static void main(String [] args) throws Exception {
String website = "http://chart.yahoo.com/c/1y/0/0005.hk.gif";

URL web = new URL(website);

Object a=web.getContent();
String b =web.getFile();

System.out.println(a);

}
}

It seem can't work becasuse i don't know how to handle image.
Any one can help me? Any one have this sample program?


Au Yiu Fai

Posts: 2
Nickname: kenneth
Registered: Apr, 2003

Re: download image by java program? Posted: Apr 8, 2003 11:00 AM
Reply to this message Reply
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?

Flat View: This topic has 1 reply on 1 page
Topic: Converting Java Previous Topic   Next Topic Topic: appendreplace

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use