error creating file android - android

When I run the app on Nexus 5 there are no problem with the file but in another smartphone I have a problem, I think it could be the spaces and I deleted it.
The code is :
File file = new File(directory,new SimpleDateFormat("dd-MM-yyyy-HH:mm:ss",Locale.ROOT).format(new Date()).toString()+"-"+idUser+"-"+idTest+".txt");
FileOutputStream outputStream = new FileOutputStream(file);
path file: /storage/sdcard0/Nexio/Tests/23-07-2014-16:33:11-alex-0.txt
The directory exists. And the exception is "FileNotFoundException"

you are probably setting directory with a static string.. that would be my guess.. use http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()

Related

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");

Android: File Location

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.

Accessing file from android data directory

i want to access the /data/local/tmp for any random access file
(RAF) file how to get the path of that file?
go this way and read the raf file line by line but be assure that the folder have read permission to other user or you can change it from adb shell by using chmod commmand .....
File finalFile = new File("/data/local/tmp", fileName);
RandomAccessFile rafTemp = new RandomAccessFile(finalFile, "r");
For accessing the any file through code , you must know the path of the file.
and then you can use the code:
File finalFile = new File/t("/data/local/tmp", fileName);
RandomAccessFile rafTemp = new RandomAccessFile(finalFile, "r");
"/data/local/tmp" is the path for the file. It can differ file to file. So you must know the path of file before accessing it.

Overwriting content of textfile in assets folder in Android project

I have a file named counter.txt in the assets folder of my Android project. At runtime I want to overwrite the content of the file. But it's not reflecting. How can I fix this problem?
I have used the below code.
String FILENAME = "counter.txt";
String string = "hello world!";
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();
As far as I know, you can't write/update in the assets folder. The only thing you can do is read.
More precisely, you can't make any changes to the 'asset' folder at runtime through your code, but after you compile your code and get the APK file, you can unzip it, change the contents of the 'asset' folder and zip all the files to APK again.
However, you must sign the APK file again to make it work.
I think you should use class SQLiteDatabase in such a case to store all your confidential but frequently updated counters.

File Not Found Exception apache common

Currently I figured out how to connect to my FTP with apache common to download things (enter IP not the ftp.xxx adress). But now I can an FileNotFound, eventhough it really is there and has everything set to 777
I already saw that apache is adding the "/" by himself so normally It should work, uploading is no problem. Any ideas? I can open the file if I enter it in my URL bar
You should create a file in your system, something like:
File f = new File("path/to/file");
if (f.exists() == false)
{
f.createNewFile();
}
FileOutputStream fos = new FileOutputStream(f.getAbsoluteFile());
client.retrieveFile("Filenametoretrieve", fos);

Categories

Resources