Solved

Java Programming question

Posted on 1997-07-05
4
461 Views
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()
        {
                try
                {
                sortURL=new                 URL("http://xxx.xx.xx/~xxxxxx/file.dat");
                connection=sortURL.openConnection();
                outStream=new PrintStream(connection.getOutputStream());
             
                }
                catch (MalformedURLException mfURLe)
                {
                        System.out.println(mfURLe);
                }
                catch (IOException ioe)
                {
                        System.out.println(ioe);
                }

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

}



0
Comment
Question by:ccst
4 Comments
 
LVL 1

Expert Comment

by:byoung
ID: 1222681
What error are you getting? That would help greatly
0
 
LVL 2

Expert Comment

by:webster030697
ID: 1222682
I think I see your problem. In your first section of code you left out:

import java.applet.*;
0
 

Author Comment

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



0
 
LVL 1

Accepted Solution

by:
froderik earned 10 total points
ID: 1222684
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.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now