博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

getResource用法

Posted on 2012-05-15 23:42  紫冰龙  阅读(267)  评论(0编辑  收藏  举报
import java.io.File;

import javax.swing.*;
public class TestResouce extends JFrame {
    public TestResouce() {
        setSize(500,500);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        String filename = TestResouce.class.getResource("TestResouce.class").getFile();
        
        JTextArea out = new JTextArea();
        out.append(filename+"\n");
        add(new JScrollPane(out));
        File file = new File(filename);
        if (file.exists()) out.append("file is exists"+"\n");
        setVisible(true);
        file.getAbsolutePath();
    }
    public static void main(String[] args) {
        new TestResouce();
    }
}