java 获取当前应用程序路径




package
javaapplication1; import javax.swing.JOptionPane; /** * * @author Administrator */ public class JavaApplication1 { public static String mystr; public static String str; /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here try{ int len; mystr = java.net.URLDecoder.decode(JavaApplication1.class.getProtectionDomain().getCodeSource().getLocation().getFile().replaceAll("/", "\\\\"),"UTF-8"); len = mystr.length(); str = mystr.substring(1,len); }catch(java.io.UnsupportedEncodingException e){ mystr = ""; str=""; } JOptionPane.showMessageDialog(null, str); } }

 

posted @ 2014-03-10 23:15  正月龙  阅读(2568)  评论(0编辑  收藏  举报
留言板