The Artima Developer Community
Sponsored Link

Java Answers Forum
Writing from URL Client to a file

0 replies on 1 page.

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 0 replies on 1 page
Carol Chilton

Posts: 1
Nickname: carol
Registered: Oct, 2002

Writing from URL Client to a file Posted: Oct 27, 2002 12:56 PM
Reply to this message Reply
Advertisement
I'm new to Java...I'm working through an example using a URL based client that can retrieve URL's. When I receive the response and write to file, I'm not getting the entire response in the file. Is there a flush from the client side too?

Here's a snippet of my code...thanks for your help.
import java.io.*;
import java.net.*;

public class URLClient {
public static void main(String[] args) throws Exception {
File outputResponseFile = new File("c:/test/response.txt");
URL u = new URL(args[0]);
URLConnection uc = u.openConnection();
BufferedReader br = new BufferedReader(
new InputStreamReader(uc.getInputStream()));
String s = br.readLine();
FileWriter out = new FileWriter(outputResponseFile);

// Write buffer to the response file
while (s != null) {
out.write(s);
s = br.readLine();
}

}
}

Topic: Parallel Port Comunication in Java Previous Topic   Next Topic Topic: Microsoft java VM

Sponsored Links



Google
  Web Artima.com   

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