Android: File Location - android

I am writing to a path mnt/sdcard/foldername. I get no errors and the file is written, but when I browse the internal storage of my phone I can not find the folder. Where would the folder be located? I have a galaxy nexus?
Code is here:
File sdCard = Environment.getExternalStorageDirectory();
File directory = new File (sdCard.getAbsolutePath() + "/statReporter/");
directory.mkdirs();
Log.d("Tag", directory.toString());
//Path and name of XML file
File file = new File(directory, appendTimeStamp("phoneNum") + ".csv");
FileOutputStream fOut = new FileOutputStream(file);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
//Write to CSV File
osw.write(message);
osw.write(',');
//Flush and close OutPutStreamWriter and close FileOutputStream
osw.flush();
osw.close();
fOut.close();
Log.d("File Logger:", "File write successfully!");
Cant find it in Windows Computer\Galaxy Nexus\Internal Storage but all other folders appear.
I used an app called OI File Managaer and I can view the folder and file on phone but how do I view it through Windows OS?

If you really want to find files on your device, I'd recommend one of the Google Play apps you can find (I personally like ASTRO File Manager) or, from the PC you can use (for instance) Android Commander (which, incidentally, will let you use the same file path structure you'll be using from within your developing environment).
I believe that Android devices will not actually show you all paths and available files when you browse it, for instance, with Windows Explorer.
If you're using Eclipse, in the DDMS perspective you can browse your device's file structure. On your right you have the "File Explorer" and as far as I remember, it's a pretty complete tool.

Don't use /mnt/sdcard for accessing external storage. You can use Environment.getExternalStorageDirectory() to access path to external storage. This may vary from device to device.

Related

Create TXT file in Android Nougat which is editable

I have created txt file which is in Internal Storage. I want to edit the file by going through file manager or any file explorer. I can update the file in Lollipop and below. but can't in Android M and Android N. It gives error as access not allowed.
File root = new File (Envirenment.getExternalStorageDirectory(),"FolderName");
if(!root.exists())
{
root.mkdirs();
}
File gpxFile = new File(root, "FileName.txt");
FileWriter writer = new Filewriter(gpxFile );
writer.append("FileBody");
writer.flush(); writer.close();
It working on all devices including Nougat, but when I going to edit from file Explorer it is not editable in Nougat. is any permission required when file is created, as readable by others?

Creating a folder with file in Android's internal storage

i'm trying to create a folder with a .csv file inside in android internal storage, but the folder doesn't appear in the regular file explorers.
The code is the following.
private String FOLDER_NAME = "app_folder";
File folder = new File(Environment.getDataDirectory().getAbsolutePath() + File.separator + FOLDER_NAME);
if( !folder.exists() )
folder.mkdir();
but the folder doesn't appear in the regular file explorers.
That is because internal storage cannot be viewed by any sort of file explorer, except on emulators or rooted devices.
File explorers — on-device and desktop — usually examine external storage.

Creating folder in the application directory

i have used getFilesDir() to create a folder in the application directory, it gives the path of the applicatoin directory as follows
/data/data/{my application package}/files
but when i use it to create a new folder using
File folder = new File(getFilesDir()
+ "/MyFolder");
if (!folder.exists()) {
folder.mkdir();
}
i don't see any folder. Also when i access in ES Explorer the actual path of the application directory is
/Android/data/{my package name}/files
My question is how to create a folder in the application directory so that it can be deleted automatically on application uninstallation.
Use method Context.getDir() instead. You don't need to invoke mkdirs(), because getDir() will do it automatically.
Quote from the documentation:
Retrieve, creating if needed, a new directory in which the application
can place its own custom data files. You can use the returned File
object to create and access files in this directory. Note that files
created through a File object will only be accessible by your own
application; you can only set the mode of the entire directory, not of
individual files.
Use this by making a use of getDir()
File dir = ctx.getDir("my_sub_dir", Context.MODE_PRIVATE);
File newfile = new File(topDirFile.getAbsolutePath() + File.separator + "new_file_name");
newfile.createNewFile();
BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(newfile));

FileOutputStream error: File not found

I know it should be a nonsense but I´m having some difficults to store a image in a custom folder. I know how to store them into the cache directory or in the camera folder, but I want to store them into a custom folder and I´m having an error. I´m using this code:
File folder = new File(Environment.DIRECTORY_DCIM + "/ExtremEye");
folder.mkdirs();
fos = new FileOutputStream(new File(folder, "FRAME_"+ nombre + ".png"));
But I´m getting this logcat:
File not found: /DCIM/ExtremEye/FRAME_20131101_120104.png: open failed: ENOENT (No such file or directory)
It´s a simple question, I know, but I have been trying different ways and I didn´t succeed.
Thanks for help!!
from the logcat seems that is trying to access DCIM in the root /, but it should be on the External storage. Try this way:
File folder = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DCIM + "/ExtremEye");

How to Create Directory in Phone Memory in android Emulator in Android

I want to create Directory in phone memory in android Emulator in android..
how to create directory in phone memory in android emulator not in SDCard
Following code can help you to create directory in phone's internal memory:
File f = new File(getFilesDir()+"/abc");
if(!f.isDirectory())
Log.d("dir", f.mkdir()? "Directory created": "Directory not created");
Actually getFilesDir() returns path to internal memory's file folder and allows you to create further files and/or directories inside.

Categories

Resources