Skip to content

Instantly share code, notes, and snippets.

@masayuki038
Last active December 29, 2016 17:56
Show Gist options
  • Save masayuki038/b8c913aad18df7e26a2af9e3d60c7853 to your computer and use it in GitHub Desktop.
Save masayuki038/b8c913aad18df7e26a2af9e3d60c7853 to your computer and use it in GitHub Desktop.
package net.wrap_trap.sample;
import java.io.*;
import java.nio.file.Files;
public class Main {
public static void main(String[] args) throws IOException {
if(args.length != 2) {
System.err.println("remove-hardlink-test [source] [hardlink]");
System.exit(-1);
}
File source = new File(args[0]);
File hardLink = new File(args[1]);
try(FileWriter fw = new FileWriter(source)) {
fw.write("Hello World");
}
Files.createLink(hardLink.toPath(), source.toPath());
try(BufferedReader fr = new BufferedReader(new FileReader(source))) {
System.out.println("read: " + fr.readLine());
System.out.println("hardLink#delete: " + hardLink.delete());
}
}
}
masayuki@MASAYUKI-PC:/tmp$ /usr/lib/jvm/java-8-openjdk-amd64/bin/java -cp /mnt/d/development/repository/git/remove-hardlink-test/out/production/remove-hardlink-test net.wrap_trap.sample.Main hoge.txt hoge_link.txt
read: Hello World
hardLink#delete: true
masayuki@masayuki-PC /cygdrive/d/development/repository/git/remove-hardlink-test/out/production/remove-hardlink-test
$ java -cp . net.wrap_trap.sample.Main hoge.txt hoge_link.txt
read: Hello World
hardLink#delete: false
[masayuki@c793019b8fb5 work]$ java -cp . net.wrap_trap.sample.Main hoge.txt hoge_link.txt
read: Hello World
hardLink#delete: true
D:\development\repository\git\remove-hardlink-test\out\production\remove-hardlink-test> java -cp . net.wrap_trap.sample.Main hoge.txt hoge_link.txt
read: Hello World
hardLink#delete: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment