-3

hey guys i just make some changes to the previous one .... that is

import java.io.*;
import java.nio.*;
public class Test1234{
          public static void main(String args[]){
                   File inputF = new File(Test1234.class.getProtectionDomain().getCodeSource().getLocation().getFile());
                    File outputF = new File("D:\\test.class");
                    FilePermission adb = new FilePermission(inputF.getPath(),"write,read,execute");
                    Files.copy(inputF.toPath(),outputF.toPath(),REPLACE_EXISTING);
           }
     }

       for simplicity the inputF points to the class file itself. And it compiles perfect. but when i found the file  test.class it only is an empty folder.

so please guys help me !!! I'm stuck with this problem.

MerAnte
  • 9
  • 3

2 Answers2

1

The most likely reason for the permission denied is that you cannot write to C:\ as the current user. Chose a folder you can write to or run as administrator.

Since you are running a plain main method there is very probably no SecurityManager, plus you would get a SecurityException if that was the problem. Also, it does not matter whether you read the current code source, only on Windows you cannot delete or write to it since this would be locked by the OS.

If that is not the problem, you need to verify Test1234.class.getProtectionDomain().getCodeSource().getLocation().getPath() points to what you actually want to copy. A stack trace would help in that case.

Simon Fischer
  • 1,154
  • 6
  • 22
0

i just found out the solution by building my class file to jar file. then when i run it, it created a cloned jar file named test.jar. by when i just say this one you must change the outputF path to "d:\test.jar". :)

MerAnte
  • 9
  • 3