Java io Stream operation demo class

1. read operation
/** *@author lxw *@date 2020/6/24 *@desc Get file input stream , Read here into memory *@param [fileName]
*@return byte[] **/ public byte[] readPdfFile(String fileName) throws
Exception{ InputStream in = null; byte[] bytesRel; try {
// read Constants.PDF_CREATE_AND_SIGN.PDF_FILE_PATH File name bit under path fileName File File f = new
File(Constants.PDF_CREATE_AND_SIGN.PDF_FILE_PATH+fileName); in = new
FileInputStream(f); //in.available It is only suitable for judging the number of bytes in the stream when reading local files , It is not suitable for the determination of stream data size in the network bytesRel =
new byte[ in.available()];; } catch (IOException e) {
log.error(" read file {} fail !"+Constants.PDF_CREATE_AND_SIGN.PDF_FILE_PATH+fileName);
throw new BizException(IfspRespCode.RESP_ERROR," read pdf File failed !"); }finally { if (in
!= null){ try { in.close(); } catch (IOException e) {
log.error(" Input stream shutdown failed ! reason :{}",e.getMessage()); } } } return bytesRel; }
2. Write file
/** *@author lxw *@date 2020/6/24 *@desc Write file If you want to improve efficiency , You can use buffered streams *@param
[pdfByte, fileName] *@return void **/ public void writePdfFile(byte[]
pdfByte,String fileName) throws Exception{ // Check whether the file already exists , Exist delete
OutputStream os = null; try { os = new
os.write( pdfByte ) ; os.flush() ; } catch (IOException e) {
log.error(" write file {} fail !"+Constants.PDF_CREATE_AND_SIGN.PDF_FILE_PATH+fileName);
}finally { try { if (os!=null) os.close(); } catch (IOException e) {
log.error(" Input stream shutdown failed ! reason :{}",e.getMessage()); } } } /** *@author lxw *@date
2020/6/23 *@desc Check whether the file exists , Delete if it exists *@param [fileName, path] *@return void **/
public void checkFIleExit(String fileName,String path){"checkFIleExit Method input parameter :fileName:{},path:{}",fileName,path); File file =
new File(path+fileName); if (file.exists()){ file.delete(); } }

©2019-2020 Toolsou All rights reserved,
( Super detail )Eclipse Using tutorials —— use Eclipse Create first HelloWorld! Database operation 5 code implementation mysql Addition, deletion, modification and query of database What can MCU do , Do you have any interesting works made by MCU or open source hardware Go to the interview after reading this , Steady over ~~ Single linked list of primary data structure (C Language implementation )SQL Comprehensive questions Employee unit comprehensive questions Python Implementation of Hanoi Tower code VHDL——JK trigger It's over , Starting salary 30k