在Android Java(API17)中读取文本文件的第一行
我对Java非常陌生,我正试图弄清楚如何从SD卡中的.txt文件中读取一行。下面的代码似乎不起作用,因为它返回一个空结果在Android Java(API17)中读取文本文件的第一行,java,android,Java,Android,我对Java非常陌生,我正试图弄清楚如何从SD卡中的.txt文件中读取一行。下面的代码似乎不起作用,因为它返回一个空结果 public static final String filePath = Environment.getExternalStorageDirectory().getPath(); public static String getProfileInfo() { String line = ""; StringBuilder sb = new StringBu
public static final String filePath = Environment.getExternalStorageDirectory().getPath();
public static String getProfileInfo() {
String line = "";
StringBuilder sb = new StringBuilder();
try{
File unzippedText = new File(filePath + "profile.txt");
BufferedReader text = new BufferedReader(new FileReader(unzippedText));
sb.append(line);
text.close();
}catch(Exception e){
e.printStackTrace();
}
return sb.toString();
}
谢谢此代码没有任何作用
sb.append(line);
行仍然等于“”
尝试使用BufferedReader.readLine
line = text.readLine (); // first line only
我的回答有用吗?如果是,请接受