Solved

Evaluate of a return Message in Java

Posted on 1997-11-19
2
152 Views
Last Modified: 2012-05-04
When I input the URL http://cameraname/io/relayon.txt in a Browser, I can switch on the relay in a camera web server. The server then gives the back the Message Relay is on that I can see in the Browser. My question is, how can I evaluate  
this Message in Java? Maybe with InputStream or DataInputStream or FileInputStream or otherwise?
I've tried it like this, but it does not work:

URL urlOpen = new URL(http://cameraname/io/relayon.txt);
URLConnection connect = urlOpen.openConnection();
connect.setDefaultAllowUserInteraction( true);
connect.setUseCaches( false );      
connect.setDoInput( true );            
connect.setDoOutput( false );       
connect.connect();

DataInputStream inputstream = new DataInputStream( connect.getInputStream()      );
                  
while( (String s=inputstream.readLine()) != null );
{
      // do whatever you want to do with s
}
inputstream.close();

Thanks, Mike
0
Comment
Question by:mkaufman
2 Comments
 
LVL 4

Accepted Solution

by:
rembo earned 20 total points
ID: 1230935

You were close:

DataInputStream dis;

URL urlOpen = new URL(http://cameraname/io/relayon.txt);

dis = new DataInputStream(urlOpen.openStream());

String s;

while ((s = dis.readLine()) != null) {
  System.out.println(s);
  //Or whatever it is you do :)
}
0
 

Author Comment

by:mkaufman
ID: 1230936
I've tried it but it does not work.
The String s is always empty. Have I maybe to wait a moment to the answer from the server?
Then I could wait for it in a Thread.

Thank Mike

0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

803 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