Java打war包or打jar包
生活随笔
收集整理的這篇文章主要介紹了
Java打war包or打jar包
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
//一個(gè)jar包可以包含多個(gè)entry,這樣就能實(shí)現(xiàn)下面功能1.I/O ? ? ? 讀文件流步驟?File file=new File(filePath);InputStreamReader read = new InputStreamReader(new FileInputStream(file));BufferedReader bufferedReader = new BufferedReader(read);String lineTxt = bufferedReader.readLine() ? ? ?package PlayJar;/*** 讀取txt文件里的路徑文件* @author gjf*/import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.InputStreamReader;import java.util.ArrayList;import java.util.List;public class ReadFile{public static List<String> readTxtFile(){String filePath = "E:/Jar/prpall.txt";List<String> list = new ArrayList<String>();try {File file=new File(filePath);if(file.isFile() && file.exists()){? ? ? ? ? ? ?//判斷文件是否存在
InputStreamReader read = new InputStreamReader(new FileInputStream(file));BufferedReader bufferedReader = new BufferedReader(read);String lineTxt = null;while((lineTxt = bufferedReader.readLine()) != null){list.add("E:/運(yùn)維域/基線域04-B/prpall/modules/webapps/"+lineTxt);}System.out.println("list"+list);read.close();}else{System.out.println("找不到指定的文件");}}catch(Exception e) {System.out.println("讀取文件內(nèi)容出錯(cuò)");e.printStackTrace();}return list;}}package PlayJar;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.util.jar.JarEntry;import java.util.jar.JarOutputStream;/*** 把單個(gè)txt里的路徑文件打包* @author pc*/public class PJar {public static void main(String[] args) throws IOException {FileInputStream fis = null;JarOutputStream jos = null;jos = new JarOutputStream(new FileOutputStream("E:/Jar/ppp.jar"));for (String s : ReadFile.readTxtFile()) {File file = new File(s);// 文件地址
fis = new FileInputStream(file);// 創(chuàng)建壓縮文件中的條目,subString是為了截距掉前面的路徑
JarEntry enttry = new JarEntry(file.getPath().substring(38));System.out.println("創(chuàng)建壓縮文件中的條目 :" + enttry);// 將創(chuàng)建好的條目加入到壓縮文件中
jos.putNextEntry(enttry);// 寫入當(dāng)前條目所對(duì)應(yīng)的具體內(nèi)容
byte[] buff = new byte[1024];int len = 0;while ((len = fis.read(buff)) != -1) {jos.write(buff, 0, len);}}fis.close();jos.close();}}
?
轉(zhuǎn)載于:https://www.cnblogs.com/guoziyi/p/7457769.html
總結(jié)
以上是生活随笔為你收集整理的Java打war包or打jar包的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: matlab logistic拟合,用m
- 下一篇: 290.Word Pattern