Я хочу прочитать текстовый файл и показать его в текстовом редакторе, но я не знаю, где разместить текстовый файл в проекте, и после этого, как я могу вызвать текстовый файл для читать и писать?Как я могу использовать текстовый файл
Я получаю ошибку No such file or directory
.
Это то, что я сделал до сих пор:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtEditor=(EditText)findViewById(R.id.textbox);
readTextFile("test.txt");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public String readTextFile(String fileName) {
String returnValue = "";
FileReader file = null;
try {
file = new FileReader(fileName);
BufferedReader reader = new BufferedReader(file);
String line = "";
while ((line = reader.readLine()) != null) {
returnValue += line + "\n";
}
txtEditor.setText(reader.toString());
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (file != null) {
try {
file.close();
} catch (IOException e) {
// Ignore issues during closing
}
}
}
return returnValue;
}
или он может chage txtEditor.setText (reader.toString()); с txtEditor.setText (returnValue); – Blackbelt