将文件写入到本地磁盘-IO流使用


       /**
	 * 将文件写入到本地磁盘
	 * @param dirPath	目录路径
	 * @param fileName	文件名,包含文件后缀
	 * @param buffer 	文件
	 * @return	文件路径
	 */
	public String writeToFile(String dirPath, String fileName, String buffer) {
		String NCHome = RuntimeEnv.getInstance().getProperty(RuntimeEnv.SERVER_LOCATION_PROPERTY);
		dirPath = NCHome + File.separator + "upload";
		File file = new File(dirPath);
		if (!file.exists()) {
			file.mkdirs();
		}
		SimpleDateFormat df = new SimpleDateFormat("_yyyy_MM_dd_HHmmss");
		fileName = fileName + df.format(new Date());
		String filePath = dirPath + File.separator + fileName;
		try {
			OutputStream out = new FileOutputStream(filePath);
			Writer writer = new java.io.OutputStreamWriter(out, "UTF-8");//UTF-8,GB2312
			writer.write(buffer.toString());
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return filePath;
	}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM