JDK-6553826 : File{Input,Output}Stream. throws IOException for socket files, on Linux/Unix
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: generic
  • Submitted: 2007-05-04
  • Updated: 2012-01-11
  • Resolved: 2007-08-08
Related Reports
Duplicate :  
Description
There are several types of files in Unix world: regular files, directories, char and block devices, named pipes and socket files. I'm trying to work with a socket file to communicate with another (non-Java) process. Method exists() for such file returns true, however when I try to create a corresponding FileInputStream or FileOutputStream I get an IOException: "No such device or address".

To reproduce the problem, launch the following test (with a modified file name):

import java.io.*;

public class TestSocketFile
{
  public static void main(String[] args)
    throws IOException
  {
    File f = new File("FILENAME");
    System.err.println("File exists: " + f.exists()); // <-- returns true
    FileInputStream fin = new FileInputStream(f); // <-- IOException is thrown
    FileOutputStream fout = new FileOutputStream(f); // <-- IOException is thrown
  }
}

(Just an example of socket file: when running X server, get the value of $XSESSION_MANAGER environment variable and look at the 'local/hostname:/path/to/file' entry - on my desktop it points to something like /tmp/.ICE-unix/12345 which is a socket file).

Comments
EVALUATION The programming model for UNIX domain sockets is a socket rather than file API. The file system is only used as a "naming service" for the socket address. The RFE tracking the requirement to add UNIX domain socket support is 4145756.
23-05-2007

WORK AROUND I haven't found any workaround for this problem. java.net.Socket class also doesn't provide any API to work with unix socket files.
04-05-2007