File Not Found Exception apache common - android

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

Related

error creating file 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()

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.

Install .APK from Android Cache

I have problems installing an APK saved in Android internal Cache.
There are no issues saving the file in External Storage or on External Cache using context.getExternalCacheDir().
But if I try to use context.getCacheDir(), the log returns
/data/data/com.my.package/cache/update.apk: open failed: EACCES (Permission denied)
File file = context.getCacheDir();
File outputFile = new File(file, "update.apk");
if(outputFile.exists()){
outputFile.delete();
}
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
Intent intent = new Intent(Intent.ACTION_VIEW);
//SAVE IN CACHE
intent.setDataAndType(Uri.fromFile(outputFile), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // without this flag android returned a intent error!
context.startActivity(intent);
It looks like internal cache doesn't allow the APK to be correctly read.
The fact is, if the file is saved on the External Storage or external Cache the APK will be available to the user, and I don't want that.
What can it be don to save the file in internal Cache?
Thanks
It looks like internal cache doesn't allow the APK to be correctly read.
That is because the installer app has no rights to read your file.
The fact is, if the file is saved on the External Storage or external Cache the APK will be available to the user, and I don't want that.
Then do not install it on the user's device. Any user can copy any APK off their device at any time after installation, so the only way to prevent the user from accessing the APK is to not have it on the device in the first place.
What can it be don to save the file in internal Cache?
Probably nothing. If you switch to openFileOutput(), you can see if MODE_WORLD_READABLE will be sufficient for the installer to proceed. Again, this will not stop the user from being able to access the APK file.
Try to look chmod command to get read\write permissions on internal folder... As for linux it looks like...
chmod 777 /data/data/*** or chmod 644 /data/data/***

Unzipping zip file gives "java.util.zip.ZipException: Cannot read version" or "java.util.ZipException Cannot read local header version 45"

I would like just to extract a normal zip file, but it keeps failing.
This is my code I'm using now:
private File downloadPath = new File(Environment.getExternalStorageDirectory() + "/Test/file.zip");
private File unzipLoc = new File(Environment.getExternalStorageDirectory() + "/Test/");
FileInputStream fin = new FileInputStream(downloadPath);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null)
{
FileOutputStream fout = new FileOutputStream(unzipLoc + ze.getName());
for (int c = zin.read(); c != -1; c = zin.read())
{
fout.write(c);
}
zin.closeEntry();
fout.close();
}
zin.close();
It fails on the 'zin.getNextEntry()' part.
Error: java.util.zip.ZipException: Cannot read version
Any ideas? Thx!
Looks like your zip file is newer than your 'unzipping library'.
If you read the source:
ZipInputStream (search for new ZipException("Cannot read version"))
It shows you it checks the zip files version. Then looking at Wikipedia it shows this is the minimum version needed to extract the zip.
Check your zip file and re-save it with a lower version of your zip software / zip it again with no compression to test
Alternately update your Zip library (which you can't do as your using the internal android zip library).
Just to add to the above answers for the solution to the problem and why was it created in my case. Yes Special thanks to Mr Bungle and Mr Blundell in helping to understand and solve the problem quickly.
I encountered this exception stating "java.util.ZipException Cannot read local header version 45" while I was unzipping files on an SDCard. The zip file was downloaded from the DOT NET Server, and the server was using SharpZipLib library to unzip the files. From the exception it clearly means that the zipping and unzipping libraries have a different version.
Solution:
Basically the library SharpZipLib uses Zip64 (extended format of zip file format to zip the files) Which is incompatible with java.util.zip package available in android and on Java releases prior to 7.
So if you switch of the Zip64 on the server which is zipping the files then it will become compatible with the android java.util.zip package and will easily be unzipped. If you add the following line on the server it will solve your problem:
ZipOutputStream.UseZip64 = UseZip64.Off

Categories

Resources