Nilesh Agrawal
Nilesh Agrawal

Reputation: 3052

Checking where the file is stored in android?

I am writing a log data to the File in android. But I am unable to understand where this file is stored on my android device ( google nexsus 7 ). Where and How should I look for the contents of the file ?

Following is the piece of code I am using to write log data to the file.

public File AppendingLog(String LogData){


        try {
            File logFile = new File(Environment.getExternalStorageDirectory(),
                    "yourLog.txt");
            if (!logFile.exists()) {
                try {
                    logFile.createNewFile();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            try {
                BufferedWriter buf = new BufferedWriter(new FileWriter(logFile,
                        true));
                buf.append(LogData);
                buf.newLine();
                buf.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
                  e.printStackTrace();
        }


        return logFile;
    }

Upvotes: 0

Views: 38

Answers (3)

nitin
nitin

Reputation: 591

I think answers below are what you need.
You can also download Astro File Manager App which will also give you an idea where your files go on Android System.

Upvotes: 0

Gladiator Boo
Gladiator Boo

Reputation: 189

android.util.Log.d("myapp", logFile.toString());

Upvotes: 1

FD_
FD_

Reputation: 12919

On most devices, it will be in /sdcard/. The exact path will be /sdcard/yourLog.txt.

As you are using Environment.getExternalStorageDirectory(), the actual path will differ between devices. Some devices return the external sd card path, but most will return the internal sd card's path, which usually is /sdcard/.

Upvotes: 1

Related Questions