【发布时间】:2017-01-07 00:53:11
【问题描述】:
我正在尝试找出我在 Android 应用程序中的一些代码存在的问题。我正在尝试从 EditText (几个框)中写一些文本。我有两个错误,并且一次又一次地查看它,但无法弄清楚我哪里出错了。我可能已经盯着它太久了。
我有错误的那一行是加粗的文本。另外,directory.close()
file = new FileOutputStream(view); OutputStreamWriter outputstreamwriter = new OutputStreamWriter(文件);
代码:
try
{
File directory = new File(Environment.getExternalStorageDirectory(), "/Car/");
directory.mkdirs();
File file = new File(directory, "Car.txt");
file.createNewFile();
**file = new FileOutputStream(view);
OutputStreamWriter outputstreamwriter = new OutputStreamWriter(file);**
outputstreamwriter.append((new StringBuilder()).append(txtName.getText()).append("\n").append("\n").toString());
outputstreamwriter.append((new StringBuilder()).append(txtAddress.getText()).append("\n").append("\n").toString());
outputstreamwriter.append((new StringBuilder()).append(txtEmail.getText()).append("\n").append("\n").toString());
outputstreamwriter.append((new StringBuilder()).append(txtPhone.getText()).append("\n").append("\n").toString());
outputstreamwriter.append((new StringBuilder()).append(txtDesc.getText()).append("\n").append("\n").toString());
outputstreamwriter.close();
directory.close();
}
// Misplaced declaration of an exception variable
catch (IOException ex)
{
Toast.makeText(getApplicationContext(), "balls", Toast.LENGTH_SHORT).show();
}
感谢您提供的任何帮助或见解。
谢谢。
【问题讨论】:
-
您是否检查过您是否拥有写入外部存储所需的权限?