Java Utililty Methods File Link

List of utility methods to do File Link

Description

The list of methods to do File Link are organized into topic(s).

Method

booleanisSymLink(File file)
is Sym Link
return Files.isSymbolicLink(file.toPath());
booleanisSymlink(final File file)
Determines whether the specified file is a Symbolic Link rather than an actual file.
if (file == null) {
    throw new NullPointerException("File must not be null");
if (File.separatorChar == '\\') {
    return false;
File fileInCanonicalDir = null;
if (file.getParent() == null) {
...
BooleanisSymlinkJava7(@Nonnull File file)
is Symlink Java
try {
    Object path = File.class.getMethod("toPath").invoke(file);
    return (Boolean) Class.forName("java.nio.file.Files")
            .getMethod("isSymbolicLink", Class.forName("java.nio.file.Path")).invoke(null, path);
} catch (NoSuchMethodException x) {
    return null; 
} catch (Exception x) {
    throw (IOException) new IOException(x.toString()).initCause(x);
...
voidmakeSymLink(File target, File destination)
Make a link

Make a link using the system's ``ln`` command.

if (!Files.exists(destination.toPath())) {
    Files.createSymbolicLink(destination.toPath(), target.toPath());
FilereadSymbolicLink(@Nonnull File symlink)
Reads the target of the symbolic link
final java.nio.file.Path path = java.nio.file.Files.readSymbolicLink(symlink.toPath());
return path.toFile();
StringreadSymlinkTarget(File file)
read Symlink Target
try {
    return Files.readSymbolicLink(Paths.get(file.getAbsolutePath())).toString();
} catch (IOException e) {
    return null;
FileresolveSymbolicLink(File file)
resolve Symbolic Link
Path path = file.toPath();
return Files.isSymbolicLink(path) ? Files.readSymbolicLink(path).toFile() : file;
StringsanitizeUrl(String link)
Make sure an URL is "portable", in that it doesn't contain bad characters that break the open command in some OSes.
link = link.trim();
if (link.startsWith("\\url{") && link.endsWith("}")) {
    link = link.substring(5, link.length() - 1);
link = link.replaceAll("\\+", "%2B");
try {
    link = URLDecoder.decode(link, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException ignored) {
...
byte[]textLinksInBytes()
text Links In Bytes
Formatter formatter = new Formatter();
formatter.format(FILE_FORMAT, "http://mirror.internode.on.net/pub/test/50meg.test", "50meg.test")
        .format(FILE_FORMAT, "http://test.online.kz/download/swf.rar", "example.rar")
        .format(FILE_FORMAT, "http://test.online.kz/download/swf.rar", "swf.rar");
return formatter.toString().getBytes(StandardCharsets.UTF_8);