1、流转字符串
public static String insToStr(InputStream cIns, String cEncoding) {
String tStr = "";
StringBuffer tSb = new StringBuffer();
if (cIns == null) {
System.out.println("传入的Ins为null");
return tStr;
}
InputStreamReader insReader = new InputStreamReader(cIns,cEncoding);
int line;
char [] c = new char[1];
while ((line = insReader.read(c)) != -1) {
tSb.append(c);
}
tStr = tSb.toString();
cIns.close();
return tStr;
}
2、流转dom
public static Document produceXmlDoc(InputStream is)
{
Document doc = null;
DOMBuilder domB = new DOMBuilder();
doc = domB.build(is);
return doc;
}
3、字符串转流
public static InputStream strToIns(String cStr, String cEncoding) {
InputStream tIns = null;
try {
byte[] b = cStr.getBytes(cEncoding);
tIns = new ByteArrayInputStream(b);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
return tIns;
}