标签:out static fileutils leo write 保存图片 utils creat void
package Http;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
/**
*
* 本地文件操作工具类
*保存文本
*保存图片
* Created by lxj-pc on 2017/6/27.
*/
public class FileUtils {
public static void saveText(String content,String dirPath,String fileName){
//保存文本
File dir =new File(dirPath);
try {
FileWriter fileWriter=new FileWriter(new File(dir,fileName));
fileWriter.write(content);
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void saveImg(byte[] bytes,String dirPath,String fileName)throws IOException{
File dir =new File(dirPath);
if(!dir.exists()){
dir.mkdirs();
}
FileOutputStream fos=new FileOutputStream(new File (dir,fileName));
fos.write(bytes);
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.printf("图片保存成功");
}
}
标签:out static fileutils leo write 保存图片 utils creat void
原文地址:http://www.cnblogs.com/lxj666/p/7087471.html