#Symlink behaviour on windows/mac

2 messages · Page 1 of 1 (latest)

wintry yew
#

Can someone with a Windows/Mac computer run this Java code? I would like to know whether symlink works the same on theses systems.

The expected behaviour is:

  • source/text.txt and linked/text.txt are created with content "hello world"
  • Editing source/text.txt (and saving the file) will change the content in linked/text.txt, and vice versa

Failure if:

  • not the expected behaviour, or
  • any errors

delete both folders before running again

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class App {
    public static void main(String[] args) throws IOException {
        Files.createDirectory(Path.of("source"));
        Files.createSymbolicLink(Path.of("linked"), Path.of("source"));
        Files.writeString(Path.of("linked/text.txt"), "hello world");
    }
}
carmine venture
#

on windows it works but only when running as administrator