首先注意
"/word/appointDismiss.docx" 前面一定要加 /,有一次我就是忘记加/ 查了半天错, 不能写成 "word/appointDismiss.docx"
System.out.println(" url:" + this.getClass().getResource("/word/appointDismiss.docx") );
System.out.println( (" path:" + this.getClass().getResource("/word/appointDismiss.docx").getPath() );
System.out.println((" file:" + this.getClass().getResource("/word/appointDismiss.docx").geFile() );
打印结果:
url:file:/C:/Users/jinpeng.bu/Documents/cas/target/classes/word/appointDismiss.docx
path: /C:/Users/jinpeng.bu/Documents/cas/target/classes/word/appointDismiss.docx
file: /C:/Users/jinpeng.bu/Documents/cas/target/classes/word/appointDismiss.docx