Solved

Java Programming question

Posted on 1997-07-05
4
475 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

830 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