去掉换行符的读取方法:
public static String readFileWithoutN(File path,String filename)
{
StringBuffer sb = null;
try {
File file = new File(path,filename);
BufferedReader br = new BufferedReader(new FileReader(file));
String readline = "";
sb = new StringBuffer();
while ((readline = br.readLine()) != null) {
System.out.println("readline:" + readline);
sb.append(readline);
}
br.close();
Log.i(TAG, sb.toString());
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
原样读取的方法:
public static String readFile(File path,String filename) {
String result = null;
try {
File file = new File(path, filename);
if (!file.exists()) {
return null;
}
FileInputStream inputStream = new FileInputStream(file);
byte[] b = new byte[inputStream.available()];
inputStream.read(b);
result = new String(b);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}