Malfunction
Malfunction

Reputation: 1334

android bufferedwriter error

I'm working on an android app where I need to create a file and write/read on it using bufferedwrite and bufferedread. The file is declared in the activity as follows:

String string = "string";
File file = new File(this.getFilesDir(), string);

When I try to write to the file using this code, however:

    BufferedWriter out = new BufferedWriter(new FileWriter(new File(file)));
    out.write("I am a line of text written in" + file);
    out.close();

I keep getting a "constructer File(File) is undefined" error. I believe the error has to do with the file declaration, but I'm not sure why.

Any help is greatly appreciated.

Upvotes: 0

Views: 523

Answers (1)

Matt
Matt

Reputation: 690

String string = "string";
File file = new File(this.getFilesDir(), string);

BufferedWriter out = new BufferedWriter(new FileWriter(file));
out.write("I am a line of text written in" + file);
out.close();

Upvotes: 1

Related Questions