如何使用getresourcepath()获取相对路径

时间:2014-03-20 04:36:32

标签: java filepath

而不是/asm/Hello.class它必须像/home/lpl/eclipse/asm/bin/asm/Hello.class这样的完整路径工作,请任何人帮我解决这个问题。

 public static void main(String[] args) throws IOException 
 {
    InputStream in = Hello.class.getResourceAsStream("/asm/Hello.class");

    ClassReader classReader = new ClassReader(in);
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);

    //Wrap the ClassWriter with our custom ClassVisitor
    ModifierClassWriter mcw = new ModifierClassWriter(Opcodes.ASM4, cw);
    classReader.accept(mcw, 0);

    //Write the output to a class file
    File outputDir = new File("bin/asm");
    outputDir.mkdirs();

    DataOutputStream dout = new DataOutputStream(new FileOutputStream(new File(outputDir,"Hello.class")));

    dout.write(cw.toByteArray());
 }

1 个答案:

答案 0 :(得分:0)

尝试类似于此的内容以获取文件的绝对路径。

import java.io.File;


File temp = File.createTempFile("i-am-a-temp-file", ".tmp" );

String absolutePath = temp.getAbsolutePath();