/**
*
* @todo 一定要确定读取的文件为utf-8格式要不然会出错,用ue可以转换成utf-8
* @param name
* String
* @return String
*/
public String getTextByUTF(String name) {
String strReturn = "";
int ic;
InputStream in = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
byte[] myData;
byte[] buffer = new byte[1024];
try {
in = getClass().getResourceAsStream(name);
if (in != null) {
while ((ic = in.read(buffer)) > 0) {
dos.write(buffer, 0, ic);
}
myData = baos.toByteArray();
strReturn = new String(myData, "UTF-8");
in.close();
}
dos.close();
baos.close();
} catch (Exception e) {
System.out.println("getTextByUTF Error:" + e.toString());
} finally {
in = null;
dos = null;
baos = null;
}
return strReturn;
}
*
* @todo 一定要确定读取的文件为utf-8格式要不然会出错,用ue可以转换成utf-8
* @param name
* String
* @return String
*/
public String getTextByUTF(String name) {
String strReturn = "";
int ic;
InputStream in = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
byte[] myData;
byte[] buffer = new byte[1024];
try {
in = getClass().getResourceAsStream(name);
if (in != null) {
while ((ic = in.read(buffer)) > 0) {
dos.write(buffer, 0, ic);
}
myData = baos.toByteArray();
strReturn = new String(myData, "UTF-8");
in.close();
}
dos.close();
baos.close();
} catch (Exception e) {
System.out.println("getTextByUTF Error:" + e.toString());
} finally {
in = null;
dos = null;
baos = null;
}
return strReturn;
}