How to post audio file to server in android - android

I need to post Audio file(picking from Audio/* intent) to server.here i got Uri, but the posting param type is File. I Used below code but it shows /directory/.. is not a absolute path and getting FileNotFoundException. Any one suggest me..
Code :
Uri uri=data.getData();
File f=new File(uri.getPath());
Log:
09-26 21:20:19.735: I/System.out(920): java.io.FileNotFoundException: /document/audio:5257: open failed: ENOENT (No such file or directory)

(this is a duplicate)
See here:
Convert file: Uri to File in Android
Don't use Uri::ToString() and use Uri::getPath() instead.

Related

Why am I getting file not found error even when file is in that location? Does it has to do something with the file path not given properly?

Caused by: java.io.FileNotFoundException: /RecordsKeeper/address/src/main/res/config.properties: open failed: ENOENT (No such file or directory)
I am getting the above error while I run my application. I am not able to load my config.properties file from config.java while I'm running my android application. Although it gets loaded and works fine when I run my library test cases using that config file.

csv FileNotFoundException: ENOENT

I am trying to access a csv file from the assets for my app and all I get is FileNotFoundException. I get the same when I try to access it from elsewhere. Any idea what I should be doing here?
Log messages work just fine until then. The error on the logcat is as follows.
Tag Text
System.err java.io.FileNotFoundException C:\Users.....\assets\cms.csv: open failed ENOENT (no such file or directory)
for the code:
br = new BufferedReader(new FileReader
("C:\\Users\\Srihari\\workspace\\CMSHealthcare\\assets\\cms.csv"));
Any help is appreciated!
Thanks in advance!
Dont point it to the file system on your computer...instead use the getAssets method to target the filesytem in the raw folder that gets bundled into your apk (the binary of the app)
br = new BufferedReader(new InputStreamReader(getAssets().open("cms.csv")));

W/DownloadManager( 7621): Aborting request for download 11:

E/UpdatesSettings( 7146): File write failed: java.io.IOException: open failed: EBUSY (Device or resource busy)
I/DownloadManager( 7621): Initiating request for download 11
W/DownloadManager( 7621): Aborting request for download 11: while opening destination file: java.io.FileNotFoundException: /storage/sdcard0/sysupdater/***.partial: open failed: EBUSY (Device or resource busy)
D/DownloadManager( 7621): cleanupDestination() deleting /storage/sdcard0/sysupdater/***.partial
I use DownloadManager to download file,sometimes it come out like this. Can anyone tell me why and how to solve this problem??
I've encountered a similar problem.
To avoid FileNotFoundException, make sure you:
Add the required permissions to write to external storage (if that's where you're trying to save), add the following into the AndroidManifest.xml:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Create the subfolder you're attempting to download into:
File folder = new File(FOLDER_PATH);
if (!folder.exists()) {
folder.mkdir();
}

java.io.FileNotFoundException: /sdcard/DCIM/ROBIN.jpg (No such file or directory)

I'm getting an error on the following line of code:
FileInputStream is = new FileInputStream("/sdcard/DCIM/ROBIN.jpg");
The error is:
java.io.FileNotFoundException: /sdcard/DCIM/ROBIN.jpg (No such file or directory)
But the image is present in the directory
My USB connection is Charge only
Never hardcode paths like /sdcard. For example, /sdcard is wrong on most Android devices. Use Environment.getExternalStorageDirectory() to find the root of external storage.
Make sure you have set the permission WRITE_EXTERNAL_STORAGE in your manifest.

FileNotFoundException: path (reason) - where can I find all possible "reason" messages?

Starting from Android 2.2, the FileNotFoundException contains additional information about problem:
java.io.FileNotFoundException: /foo/bar (No such file or directory)
The error message format is:
java.io.FileNotFoundException: path (reason)
I have seen such reasons:
Invalid argument
No space left on device
No such file or directory
Permission denied
Read-only file system
Q: Where can I find all possible reason messages? Documentation, or the source file where they are thrown from.
Exceptions like this are sort of generic, used by other classes, and will generally not contain the "reasons" that you mentioned. Any class could use a java.io.FileNotFoundException exception, so in order to find all of the possible "reasons" you would need to search the Android source code for something like throws FileNotFoundException or new FileNotFoundException.

Categories

Resources