1 昨天寫的文件Copy
InputStream classpathIs = CopyJar.class.getResourceAsStream("/.classpath");
//也可以這麼寫
InputStream classpathIs = CopyJar.class.getResourceAsStream("/.classpath");
//下面這麼寫是正確的,
InputStream classpathIs = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/apache/commons/logging/Log.class");
虛擬機就用用這個方法來加載字節碼,然後鏈接的。
從Classpath中加載資源,比如可以加載.class文件,但是不能從Classpath之外的路徑加載資源。
2 使用jdom讀取xml
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(classpathIs);
List<Element> lst = doc.getRootElement().getChildren();
Element.getAttribute()
Element.getAttributeValue()
3 複製文件,先讀取一個InputStream,然後輸出一個OutputStream
InputStream is = new FileInputStream(inputPath);
File file = new File(outputPath);
if(file.isExist()) {
file.delete()
file.createNewFile();
}
while(is.avialiable()!=0){
byte[] buffer=new byte[1024*100];
is.read(buffer);
os.write(buffer);
}
is.close();
os.close();
讀文件的主要瓶頸還是在打開文件,關閉文件上,文件Copy不是非常費時。
新開一個FileOutputStream,可以覆蓋掉原來的File。
4今天遇到的在Tomcat裏面ClassNotDef問題。(沒有解決)
5WebService。使用AXIS或CXF(等到週末有時間來搞一搞)
6MVN的插件編寫,看能不能寫一個直接打包,打包後,能直接放到Tomcat裏面去的插件。
7 mvn taobaodoc:transform
mvn eclipse:eclipse
mvn eclipse:clean