Solved

Java Programming question

Posted on 1997-07-05
4
481 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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:
This video teaches viewers about errors in exception handling.

728 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