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).
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).
- duplicates
-
JDK-4145756 connecting between Java socket and Unix Domain socket.
- Closed