JSD-8024 开源任务材料
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

65 lines
1.8 KiB

package com.fr.plugin.it.utils;
import java.io.*;
public class IOUtils {
/**
* 将inputStream写入本地文件
* @param url
* @param inputStream
*/
public static void writeFile(String url, InputStream inputStream){
int index;
byte[] bytes = new byte[1024];
FileOutputStream downloadFile = null ;
try {
downloadFile = new FileOutputStream(url);
while ((index = inputStream.read(bytes)) != -1) {
downloadFile.write(bytes, 0, index);
downloadFile.flush();
}
}catch(Exception e){
FRUtils.FRLogInfo("Exception:writeFile:"+e.getMessage());
}finally {
try {
inputStream.close();
downloadFile.close();
}
catch (Exception e){
FRUtils.FRLogInfo("Exception:writeFile:finally"+e.getMessage());
}
}
}
/**
* 字符串转输入流
* @param str
* @return
*/
public static InputStream strToInputStream(String str){
try {
return new ByteArrayInputStream(str.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
FRUtils.FRLogInfo("IOUtils-strToInputStream:exception:"+e.getMessage());
}
return null;
}
public static String inputStreamToStr(InputStream inputStream) {
StringBuffer stringBuffer = new StringBuffer();
byte[] byt = new byte[4096];
try {
for (int i; (i = inputStream.read(byt)) != -1; ) {
stringBuffer.append(new String(byt, 0, i));
}
}catch(Exception e){
FRUtils.FRLogInfo("Exception:inputStreamToStr:"+e.getMessage());
}
return stringBuffer.toString();
}
}