public static void createHardLink ( File file , File linkName ) throws IOException { if ( file == null ) { throw new IOException ( "invalid arguments to createHardLink: source file is null" ) ; } if ( linkName == null ) { throw new IOException ( "invalid arguments to createHardLink: link name is null" ) ; } // construct and execute shell command String [ ] hardLinkCommand = getHardLinkCommand . linkOne ( file , linkName ) ; Process process = Runtime . getRuntime ( ) . exec ( hardLinkCommand ) ; try { if ( process . waitFor ( ) != 0 ) { String errMsg = new BufferedReader ( new InputStreamReader ( process . getInputStream ( ) ) ) . readLine ( ) ; if ( errMsg == null ) errMsg = "" ; String inpMsg = new BufferedReader ( new InputStreamReader ( process . getErrorStream ( ) ) ) . readLine ( ) ; if ( inpMsg == null ) inpMsg = "" ; throw new IOException ( errMsg + inpMsg ) ; } } catch ( InterruptedException e ) { throw new IOException ( e ) ; } finally { process . destroy ( ) ; } }
Creates a hardlink