getUrl2() {
// ListurlList = new ArrayList<>();
// String filePath = getPath();
// Sheet sheet = null;
// Workbook workbook=null;
// Row row = null;
// int rownum = 0;//行数
// int colnum = 0;//列数
// InputStream in = null;
// try {
// File file = new File(filePath);
// in = new FileInputStream(file.getAbsolutePath());
// try {
// workbook = WorkbookFactory.create(in);
// } catch (InvalidFormatException e) {
// e.printStackTrace();
// }
//
// int sheet_size = workbook.getNumberOfSheets();
// System.out.println("sheet_size:" + sheet_size);
// for (int i = 0; i < sheet_size; i++) {
// sheet = workbook.getSheetAt(i);
// rownum = sheet.getPhysicalNumberOfRows();//获取行数
// row = sheet.getRow(0);//获取第一行,之后获得列数
// colnum = row.getPhysicalNumberOfCells();//获得列数
// for (int j = 1; j < rownum; j++) {
// row = sheet.getRow(j);
// if (row != null) {
// for (int k = 0; k < colnum; k++) {
// Cell cell = row.getCell(k); //这里已经确认将要获取的数据是String类型,所以不用判断Cell的类型
// String url = cell.getStringCellValue();
// System.out.println("j---------》》》"+url);
// urlList.add(url);
// if (url.equals("") || url == null) {
// } else {
// urlList.add(url);
// }
// url = null;
// }
// }
// }
sheet=workbook.getSheetAt(i);
for (int j = 0; j < sheet.getPhysicalNumberOfRows(); j++) { //行数
for (int k = 0; k < ; k++) {
String url=sheet.getCell(k,j).getContents();
// System.out.println("i,j:"+url);
if (url.equals("")||url==null){
}else {
urlList.add(url);
}
url=null;
}
}
// }
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (in != null) in.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// System.out.println("filePath:" + filePath);
// return urlList;
// }
/**
* 将图片写入磁盘
*
* @param url
* @param in2outPictrue
*/
public static void getPictrue(String url, InputStream in2outPictrue) {
if (url.length() > 7) {
in2outPictrue = null;
OutputStream out = null;
String filePath = null;
String pictureType = url.substring(url.length() - 4, url.length());
if (OutPictruePath != null) {
filePath = OutPictruePath + "/" + count + pictureType;
} else {
return;
}
File file = new File(filePath);
in2outPictrue = getPictrueInputStream(url, in2outPictrue);
if (in2outPictrue != null) {
try {
out = new FileOutputStream(file);
byte[] b = new byte[1024];
int n = 0;
while ((n = in2outPictrue.read(b)) != -1) {
out.write(b, 0, n);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (out != null) out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
System.out.println("in2outPictrue is null!");
return;
}
System.out.println(pictureType);
} else {
return;
}
}
/**
* 创建URL连接,获取图片输入流
*
* @param url
* @param in
* @return
*/
public static InputStream getPictrueInputStream(String url, InputStream in) {
try {
URL urlConn = new URL(url);
try {
HttpURLConnection conn = (HttpURLConnection) urlConn.openConnection();
conn.setRequestMethod("GET");
conn.setReadTimeout(5000);
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
in = conn.getInputStream();
return in;
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}
}