We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Java Programming question

ccst asked
Medium Priority
Last Modified: 2008-03-03
what is the problem for the code?

import java.net.*;
import java.io.*;
import java.awt.*;
class sortClient
        URL sortURL;
        URLConnection connection;
        PrintStream outStream;
        public sortClient()
                sortURL=new                 URL("http://xxx.xx.xx/~xxxxxx/file.dat");
                outStream=new PrintStream(connection.getOutputStream());
                catch (MalformedURLException mfURLe)
                catch (IOException ioe)

public class test extends java.applet.Applet
        sortClient a;
        public void init()
                a=new sortClient();


Watch Question

What error are you getting? That would help greatly
I think I see your problem. In your first section of code you left out:

import java.applet.*;


When I run the applet. Error message display (java.net.ProtocolException: cannot write to a URLConnection if doOutput=false call setDoOutput(true))

You are not supposed to write to any files anywhere when using applets. The only thing an applet can do with files is reading. This is for security reasons.

If you really want to write to files you have some options. The nicest in Java is the socket solution where you have an Java aplication running on the server which you can access from Java clients, applets or applications, to read and write to files. In this way you get moch more control over the i/o process.

If you want some good resources on things like this please let me know.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.