Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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...
  /*
   * Copyright 1994-2006 Sun Microsystems, Inc.  All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Sun designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Sun in the LICENSE file that accompanied this code.
  *
  * This code is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * version 2 for more details (a copy is included in the LICENSE file that
  * accompanied this code).
  *
  * You should have received a copy of the GNU General Public License version
  * 2 along with this work; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  * CA 95054 USA or visit www.sun.com if you need additional information or
  * have any questions.
  */
 
 package java.io;

Signals that an I/O exception of some sort has occurred. This class is the general class of exceptions produced by failed or interrupted I/O operations.

Author(s):
unascribed
Since:
JDK1.0
See also:
InputStream
OutputStream
 
 public
 class IOException extends Exception {
     static final long serialVersionUID = 7818375828146090155L;

    
Constructs an IOException with null as its error detail message.
 
     public IOException() {
         super();
     }

    
Constructs an IOException with the specified detail message.

Parameters:
message The detail message (which is saved for later retrieval by the java.lang.Throwable.getMessage() method)
 
     public IOException(String message) {
         super(message);
     }

    
Constructs an IOException with the specified detail message and cause.

Note that the detail message associated with cause is not automatically incorporated into this exception's detail message.

Parameters:
message The detail message (which is saved for later retrieval by the java.lang.Throwable.getMessage() method)
cause The cause (which is saved for later retrieval by the java.lang.Throwable.getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
Since:
1.6
 
     public IOException(String messageThrowable cause) {
         super(messagecause);
     }

    
Constructs an IOException with the specified cause and a detail message of (cause==null ? null : cause.toString()) (which typically contains the class and detail message of cause). This constructor is useful for IO exceptions that are little more than wrappers for other throwables.

Parameters:
cause The cause (which is saved for later retrieval by the java.lang.Throwable.getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
Since:
1.6
 
     public IOException(Throwable cause) {
         super(cause);
    }
New to GrepCode? Check out our FAQ X