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 copy a file to another directory with code". In daily operation, I believe many people have doubts about how to copy a file to another directory with code. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to copy a file to another directory with code". Next, please follow the editor to study!
Public Map imageUpload (String path, String sensorNo,String presetNo, String channelNo)
Map map = new HashMap ()
/ / read the picture
File fileImage = new File (path); / / E:\ picture\ 1\ 20210409\ 66666.png
FileInputStream fis = null
Try {
Fis = new FileInputStream (fileImage); / / create an input stream object
} catch (FileNotFoundException E1) {
Log.error ("read file error {}", E1)
}
String fileDocment = null; / / write path
If (System.getProperty ("os.name"). ToLowerCase (). Contains ("windows")) {
BaseSysconfig baseSysconfig = baseSysconfigRepository.findByParamCode ("ElectronicfenceW")
FileDocment = baseSysconfig.getCurrentlyValue () + File.separator + "zhqb_electronicfence"
+ File.separator + sensorNo.replace ("", ") + File.separator
+ presetNo.replace ("", ") + File.separator
+ channelNo.replace (",")
} else {
/ / stitching upload path / datacenter/zhqb_electronicfence/ camera number / preset bit number / channel number / picture name
BaseSysconfig baseSysconfig = baseSysconfigRepository.findByParamCode ("ElectronicfenceL")
FileDocment = baseSysconfig+ File.separator
+ sensorNo.replace ("", ") + File.separator
+ presetNo.replace ("", ") + File.separator
+ channelNo.replace (",")
}
String filepath = fileDocment + File.separator + fileImage.getName ()
/ / write path
File fileParent = new File (fileDocment); / / New file directory
Create a path if if (! fileParent.exists ()) {/ / does not exist
FileParent.mkdirs ()
}
File fileElectronicFence = new File (filepath); / / directory to be written by filePath
FileOutputStream fos = null
If (! fileElectronicFence.exists ()) {
Try {
FileElectronicFence.createNewFile ()
Fos = new FileOutputStream (filepath)
Byte [] buf = new byte [1024]; / / amount of file data per read
Int len =-1
While ((len = (fis.read (buf)! =-1) {
Fos.write (buf)
Fos.flush ()
}
} catch (IOException e) {
Log.error ("create file error {}", e)
} finally {
Try {
Fos.flush ()
Fos.close ()
Fis.close ()
} catch (IOException e) {
Log.error ("close OutputStream fail {}", e)
}
}
}
Map.put ("status", "sucess")
Map.put ("path", filepath)
Return map
}
At this point, the study of "how to copy a file to another directory with code" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.