These days in project development, to read the contents of a text file, and therefore wrote a text file to read the contents of the method, the code is as follows:
// read the contents of the text file
public static String ReadTxtFile (String strFilePath)
{
String path = strFilePath;
String Content = ""; // string file contents
// Open a file
File File = new new File (path);
// If the path is a parameter passed over, can make a determination of non-directory
IF (file.isDirectory ())
{
Log.d ( "TestFile", "of the File Not Not does exist.");
}
the else
{
the try {
the InputStream = the FileInputStream new new inStream (File);
IF (inStream = null!)
{
InputStreamReader inputreader = new InputStreamReader(instream);
BufferedReader buffreader = new BufferedReader(inputreader);
String line;
//分行读取
while (( line = buffreader.readLine()) != null) {
content += line + "\n";
}
instream.close();
}
}
catch (java.io.FileNotFoundException e)
{
Log.d("TestFile", "The File doesn't not exist.");
}
catch (IOException e)
{
Log.d("TestFile", e.getMessage());
}
}
return content;
}
Reproduced in: https: //www.cnblogs.com/kevinGao/archive/2012/02/29/2426891.html