Filewriter问题 - Java Android

时间:2014-01-02 19:21:25

标签: java android file filewriter

我的文件编写器似乎没有创建文件。
这是我的代码:

public void peopledetails_write(ArrayList<PeopleDetails> peopledetails_file) {
        ////numbers is the arraylist of numbers.
        ///names is the arraylist of names of people.
        ///Written to file like 01235 678 908, Daniel; 01245 645 123, Bob Marley; etc.
        ///Like a CSV file. 
        try{
            FileWriter writer_file = new FileWriter("PeopleDetailsFile");

            String filestring = ""; ///initializes filestring, which is written to the file.
            for(PeopleDetails person : peopledetails_file){
                String person_detail_string = "";
                person_detail_string = person.name + "," + person.number;
                filestring = filestring + person_detail_string + ";";

            }
            writer_file.write(filestring);
            writer_file.close();
        }
            catch (IOException e) {
                Log.e("ERROR", e.toString());

        }finally{
            ///Hopefully won't get an error here.
            Intent switch_menu = new Intent(this, MenuList.class);
            startActivity(switch_menu);
        }
    }

它作用于finally,并将用户带回我的应用程序的主菜单。我已设法调试此代码所在的部分,并认为这是错误的代码,因为我得到FileNotFound exception,此部分之后应编写文件。

此代码有什么问题?

1 个答案:

答案 0 :(得分:2)

这里你出错了,除非api指向某个特定的目录,你应该总是这样  使用绝对文件路径(完整文件路径)。

FileWriter writer_file = new FileWriter(complete_file_path);