private String getContent(String filePath){
File file = new File(filePath);
FileInputStream fis = null;
String tempString = null;
BufferedReader reader = null;
Log.d(TAG,"file.exists = "+file.exists());
if (file.exists()){
try {
fis = new FileInputStream(file);
reader = new BufferedReader(new InputStreamReader(fis));
while ((tempString = reader.readLine()) != null) {
return tempString;
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}finally {
if (fis != null && reader != null){
try {
fis.close();
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
return tempString;
}
filePath: 要读取的文件路径
tempString: 读取到的内容
注意: 这是简单的读取文件,如文件内容比较复杂,需要进行转换输出!