• Post Reply Bookmark Topic Watch Topic
  • New Topic

Copy target of link in Windows  RSS feed

 
Rod Taylor
Greenhorn
Posts: 25
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

Does anyone know how to copy the target of a link? I am using Apache's FileUtils class. I have tried the following and it only copies the link, not the target:



Can anyone help me on this please? Thank you.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean copying the whole file? Look through the Java Tutorials; there is a section there about file copying. I haven't read it. I suspect it won't use the Apache class, however.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there's anything in the JRE (and thus the Oracle Java Tutorial) to help with this. http://stackoverflow.com/questions/309495/windows-shortcut-lnk-parser-in-java seems to be what you need.
 
Rod Taylor
Greenhorn
Posts: 25
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Do you mean copying the whole file? Look through the Java Tutorials; there is a section there about file copying. I haven't read it. I suspect it won't use the Apache class, however.


I tried the Java Tutorials, but it only copies the link, not the target. Then I found FileUtils from Apache, but I'm still stuck with this.
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Try to add slash at the back ("/"), to make a full path, possible that complaining about it

File destinationDirectory = new File("C:/Demo/destinationDirectory");

2. Another thing, what's possible, that windows paths are c:\ not c:/

So try like this:

String fPath = "C:\Demo\sourceDir\a_link.lnk";
String filePath = fPath.replace("\\", "\\\\") ;
File sourceFile = new File(filePath);

String dir = "C:\Demo\destinationDirectory";
String dirPath = dir.replace("\\", "\\\\") + "\\" ;
File destinationDirectory = new File(dirPath);

FileUtils.copyFileToDirectory(sourceFile, destinationDirectory);
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:2. Another thing, what's possible, that windows paths are c:\ not c:/

I'm pretty sure that's not a problem in Java. It'll accept '/' even for Windows paths - and the advantage is that they don't need escaping.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!