In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to convert java remote file url into input stream". In daily operation, I believe many people have doubts about how to convert java remote file url into input stream. Xiaobian consulted all kinds of information and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "how to convert java remote file url into input stream". Next, please follow the editor to study!
The java remote file url is converted to the input stream URL url = new URL (fileUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection (); / / the timeout is set to 3 seconds conn.setConnectTimeout (3x1000); / / the error conn.setRequestProperty ("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)") is returned while preventing the masking program from crawling; / / the input stream InputStream inputStream = conn.getInputStream () Public static AjaxModel parseExcelForInfo (InputStream inputStream, String fileName, int taskId) {try {/ / create workbook object Workbook workbook = null; if (fileName.contains (".xlsx")) {workbook = new XSSFWorkbook (inputStream);} else if (fileName.contains (".xls")) {workbook = new HSSFWorkbook (inputStream) } else {return AjaxModel.failed (- 1, "incorrect file type");} / / get the first sheet table Sheet sheetAt = workbook.getSheetAt (0); if (sheetAt! = null) {/ / TODO check excel header Row headRow = sheetAt.getRow (0); for (int I = 0; I < BusinessSettlementConstants.TEMPLATE_COULMN.length) LOGGER.info +) {if (! FileUtil.getCellFormatValue (headRow.getCell (I)). Trim (). Equals (BusinessSettlementConstants.TEMPLATE_ COULMN [I]) {LOGGER.info ("parseExcelForInfo excel header information is not in the correct order GetCellFormatValue (headRow.getCell (I)): {}, "+" BusinessSettlementConstants.TEMPLATE_ Colmn [I]: {}, taskId: {} ", FileUtil.getCellFormatValue (headRow.getCell (I)), BusinessSettlementConstants.TEMPLATE_COULMN [I], taskId) Return AjaxModel.failed ("excel header order is incorrect:" + FileUtil.getCellFormatValue (headRow.getCell (I);}} int startRowNum = sheetAt.getFirstRowNum () + 1; int lastRowNum = sheetAt.getLastRowNum () LOGGER.info ("parsing excel starts taskId: {}, from line [{}] to the end of line [{}]", taskId, startRowNum, lastRowNum); List dataList = new ArrayList (); for (int rowNum = startRowNum; rowNum)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.