invalid LOC header 與 Could not publish to the server. java.lang.IndexOutOfBoundsException 錯誤處理
由於jar 包檔案眾多, 寫了一個小工具進行迴圈排除,哪一個檔案錯誤 之後進行 update maven project 操作, 注意: 如果jar 還是下載不全, 只能自行到官網進行下載,放置本地倉庫
2. invalid LOC header 也是同樣原因
查詢錯誤檔案工具類
package com.tools;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
//注意要將檔案儲存為utf-8,txt檔案的預設儲存為ANSI.要改成urf-8不然會像file:ziptestfile/fileInZip.txt
public class ReadZip {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
ReadZip rz=new ReadZip();
File file = new File("C:\\Users\\Administrator\\.m2\\repository");
List<File> list = new ArrayList<File>();
rz.getJarFile(file, list);
for(File temp: list) {
}
}
public void getJarFile(File file, List<File> list) {
if(file.isDirectory()) {
for(File temp: file.listFiles()) {
getJarFile(temp, list);
} else if(file.getName().endsWith("jar")){
list.add(file);
}
}
public void readZipContext(String zipPath) throws IOException{
ZipFile zf = null;
try {
zf=new ZipFile(zipPath);
System.out.println(zipPath);
return ;
}
InputStream in=new BufferedInputStream(new FileInputStream(zipPath));
ZipInputStream zin=new ZipInputStream(in);
//ZipEntry 類用於表示 ZIP 檔案條目。
ZipEntry ze;
while((ze=zin.getNextEntry())!=null){
if(ze.isDirectory()){
//為空的資料夾什麼都不做
}else{
BufferedReader reader;
try {
zf.getInputStream(ze).read(new byte[1000], 0, 1000);
// reader = new BufferedReader(new InputStreamReader(zf.getInputStream(ze), "utf-8"));
// reader.close();
} catch (IOException e) {
zin.close();
in.close();
zf.close();
System.out.println(zipPath);
File file = new File(zipPath);
File fileParent = file.getParentFile();
File[] childrenFiles = fileParent.listFiles();
for(File temp : childrenFiles) {
if( temp.delete()) {
System.out.println("delete:" + temp.getAbsolutePath());
}
}
// TODO Auto-generated catch block
break;
}
}
}
}
}