[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Java and http



Sender: Magne Kofoed <magne@xxxxxxxxx>

Hi,

This is a java example that is similar to http api example1.

Maybe a good idea to start a java socket/http api group?

I posted this answer To: Java Programming on and around the 
iSeries / AS400 <java400-l@xxxxxxxxxxxx>

Hi, 

if you just want to connect to an URL, get the file (pdf, 
html...) and save it on the iSeries (or whatever system you 
are running on)....here is some test code that do so: 

java -Djava.version=1.4 URLReader <url> <path> <file> 


import java.net.*; 
import java.io.*; 

public class URLReader { 
   public static void main(String args []) throws Exception 
{ 
if (args.length < 3) { 
     System.out.println("Error !");      
System.out.println("Usage: URLReader 
[url] [path] [file]"); 
return; 
} 
   String test = args[0]; 
   String path = args[1]; 
   String filename = args[2]; 

URL yahoo = new URL(test); 
BufferedReader in = new BufferedReader( 
new InputStreamReader( 
yahoo.openStream())); 

String inputLine; 
     File outputFile = new File(path , filename); 
System.out.println("Destination: " + path); 
try{ 
PrintWriter outFileStream = new PrintWriter(new 
FileOutputStream(outputFile)); 
while ((inputLine = in.readLine()) != null)     
outFileStream.println(inputLine); 
     outFileStream.flush(); 
     outFileStream.close(); 
in.close(); 
}catch (IOException exc){ 
System.out.println("Error opening file! Does Directory 
exist?"); 
System.exit(1); 
} 
   } 
} 

Rgds, 
Magne 
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubsribe from the list send mail
to majordomo@xxxxxxxxxxxxx with the body: unsubscribe ftpapi mymailaddr
-----------------------------------------------------------------------