unable to locate file in DDMS view

I am generating a notification for classes according to my timetable. In the notification i am providing action button if the user clicks this button a file for that class opens where attendance is marked for the corresponding class. I have written the following code

   public class Record extends BroadcastReceiver
    {public void onReceive(Context context, Intent intent) 
          {
         String f = intent.getStringExtra("class");

     String fname= f+".txt";
     System.out.println("File Name :" + fname);
     try 
        {   File name = new File(f+".txt");      
            if(!name.exists())
            {
                System.out.println("Creating file" + fname);

                name.createNewFile();
                FileOutputStream fos = context.openFileOutput(fname,Context.MODE_PRIVATE);
                String str1= "1";
                fos.write(str1.getBytes());
                fos.close();
                       if(!name.exists())
                {
                    System.out.println("FILE NOT CREATED");
                }
            }

            else
            {    String inputString;
                 BufferedReader inputReader = new BufferedReader(new InputStreamReader(
                            context.openFileInput(fname)));
                    StringBuffer stringBuffer = new StringBuffer();                
                    while ((inputString = inputReader.readLine()) != null) 
                    {
                           stringBuffer.append(inputString + "\n");
                    }

                   int number = Integer.parseInt(inputString);
                   number=number+1;
                   String str1 = String.valueOf(number);
                   FileOutputStream fos = context.openFileOutput(fname,Context.MODE_PRIVATE);
                   fos.write(str1.getBytes());
                   fos.close();                                        
            }

        }

     catch(IOException e)
        {
            e.printStackTrace();
        }
 }  
      }

So what i did is check if the file exists . if not then create one else increment the contents by one.

when i run this and click on the action button, i get 1) File Name 2) Creating File

but don't get FILE NOT CREATED. this means the file is being created. But i cannot find the file in DDMS view.

I dont know where i am going wrong. Please help.

Answers


It is probably already created. Context.MODE_PRIVATE automatically creates the file in your internal app directory if not already there. The complete path to your internal app files directory is /data/data/com.example.yourpackage/files.

Is your phone rooted? Because you shouldn't be able to see the root folders in DDMS without it being rooted. If so, another way you can check is use a File Manager program on your phone. I use ES File Manager.


Try to put fname on the disk as I doubt that you are creating file in a non authorized area on the disk

Use

String fname= getFilesDir() +"/" + f+".txt";

Need Your Help

Strange behavior when putting 2 divs next to each other

html css

I want to put 2 divs next to each other centered, like described here. The problem is that it seems that my right div is always a bit under the left one when I put a <span> and a heading into...