What is considered the best, most comprehensive way to close nested streams in Java? For example, consider the setup:
FileOutputStream fos = new FileOutputStream(...)
BufferedOS bos = new BufferedOS(fos);
ObjectOutputStream oos = new ObjectOutputStream(bos);
I understand the close operation needs to be insured (probably by using a finally clause). What I wonder about is, is it necessary to e...
FileNotFoundException is thrown on all sorts of occasions - not necessarily only when the file name is invalid, but also when e. g. permissions do not allow a file to be created or read:
java.io.FileNotFoundException: \\server\share\directory\test.csv (Anmeldung fehlgeschlagen: unbekannter Benutzername oder falsches Kennwort)
at java.io.FileOutputStream.open(Native Method)
at java.io.F...
after searched for a while I still couldn't find any answer to my question, even there's couple of Generics related topic, so here you go:
ArrayList<? super IOException> list = new ArrayList<Exception>();
list.add(new FileNotFoundException("this is ok."));
list.add(new IOException("This is ok"));
list.add(new ClassCastException("compile err"));//why compile err?
list.add(new Except...
I hope you can help. Im fairly new to progamming and Im playing around with java Sockets.
The problem is the code below. for some reason commSocket = new Socket(hostName, portNumber); is returning true even when it has not connected with the server (server not implemented yet!). Any ideas regarding this situation?
For hostName Im passing my local machine IP and for port a manually selected po...
I'm writing a Java app which has a feature to check whether it's connected to the internet by periodically trying to access a server. My first idea was to Ping the server - but turned out to be complicated to achieve in Java. So I remade it to send HTTP HEAD requests and check for the HTTP response code instead. I have two questions:
1) Are HTTP HEAD requests "as reliable" as pings? Ping would...
I'm using NetBeans IDE 6.9.1 for developing java/javafx applets, this netbeans version generates only java 1.6 compatible applets. But there is needed to make applets launchable on mac_os 10.5 (where default version of jvm is 1.5). I've tried to find how may I change compile options, but had no success.
Could anybody help to solve this problem?
I am trying to create a thread to simply send the text to client. However, if you copy this code to IDE, you will see that there is a red underline under client.getOutputStream(). I do not know what is wrong here. The IDE says "Unhandled exception type IOException". Could anybody tell me?
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.n...
I am using Apache HttpClient and would like to communicate HTTP errors (400 Bad Request, 404 Not Found, 500 Server Error, etc.) via the Java exception mechanism to the calling code. Is there an exception in the Java standard library or in a widely used library that would be appropriate to use or to subclass for this purpose?
The alternative is to check status return codes. This appears to be t...
Here's the code I'm using:
public class Ser implements Serializable {
int x,y;
String name;
public Ser(int a, int b, String c) {
x=a;
y=b;
name = c;
}
}
import java.io.*;
public class testSer {
public static void main(String[] args) {
FileOutputStream testStream = new FileOutputStream("serText.ser");
ObjectOutputStream testOS = new ObjectOutputStream(testStream);
Se...
In Java how can I take the data of my file on my display screen?
I want to use data in my file and also want that data to be displayed on my output screen when I execute my program. Can any body please help by providing me such example in Java language. Thank you!
I have eyeballing this code for a long time, trying to reducing the amount of memory the code use and still it generated java.lang.OutOfMemoryError: Java heap space. As my last resort, I want to ask the community on how can I improve this code to avoid OutOfMemoryError
I have a driver/manifest file (.txt file) that contain information about the PDFs. I have about 2000-5000 pdf inside a zip fil...
Why does RAD7 give a compile error of
The constructor IOException(Exception) is undefined
on the following line
throw new IOException(ex);
The Javadoc for Java 1.6/6.0 states that IOException has a IOException(Throwable) constructor
When I look at the definition of IOException I see only the following constructors
IOException()
IOException(String)
Notes:
Rational Application D...
Suppose I catch an exception that is of type AppException but I only want to carry out certain actions on that exception if it has a nested exception of type StreamException.
if (e instanceof AppException)
{
// only handle exception if it contains a
// nested exception of type 'StreamException'
How do I check for a nested StreamException?
I need some help with understanding the IOException. I've reviewed a lot of information on the internet, and looked at the technical specifications at Oracle's Java website.
Am I correct in my understanding of the IOException class and all of it's sub-classes, that there are no associated "error messages" or "return code" values?
So if one wanted to issue some message and/or return code value...
While i am running my program i have svrSocket.accept() method..My program is automatically getting terminated when it reaches to svrSocket.accept() method.
Please suggest what needs to be done.
I have created a TCP server-client application in java which exchange periodic messages between them.
As part of failure management, i need to detect the failure of either host/client and then call my custom function.
Which exception in Java will catch just this part?
Will SocketException work here? I want to call failure management only when host/client go down and not on any other issue.
I just had a test on java and we had to give the definition of
1) Static:
2) IOExcepion:
What I said for static was...a static method is used to define a method as a class method. And I got it wrong so I asked my teacher and he said he wants the actually definition of static not a static method, class or variable just static. Can someone tell me the definition of this and for IOException ple...