public static void main(String[] args) {
File file = new File("C:\\Users\\17146\\Desktop\\a.xlsx");
FileItemFactory factory = new DiskFileItemFactory(16, null);
String textFieldName = "textField";
/**
源碼注釋
* Create a new {@link FileItem} instance from the supplied parameters and
* any local factory configuration.
*
* @param fieldName The name of the form field.
* @param contentType The content type of the form field.
* @param isFormField <code>true</code> if this is a plain form field;
* <code>false</code> otherwise.
* @param fileName The name of the uploaded file, if any, as supplied
* by the browser or other client.
*
* @return The newly created file item.
*/
FileItem item = factory.createItem(textFieldName, "text/plain", true, "C:\\Users\\17146\\Desktop\\a.xlsx");
int bytesRead = 0;
byte[] buffer = new byte[8192];
try {
FileInputStream fis = new FileInputStream(file);
OutputStream os = item.getOutputStream();
while ((bytesRead = fis.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
MultipartFile multipartFile = new CommonsMultipartFile(item);
//這是封裝pio 將 excel 讀取成二位字符串數組 只做類型轉換請忽略下面代碼
List<String[]> list = readGameExcel(multipartFile);
for (String[] strings:list ) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < strings.length; i++) {
sb.append(Strings.nullToEmpty(strings[i]));
}
if(Strings.isNullOrEmpty(sb.toString().replaceAll(" ",""))){
continue;
}else {
for (String s : strings) {
System.out.print(s + "---");
}
}
System.out.println();
}
}