I download a pdf file from server with web service and save it in a file
then i try to open the file by PDFViwer but it dosent open
then i open eclipse file exploer i see the file permission is "-rw-----"
i try to change exec permission but it dosent
File myDir = new File(getFilesDir().getAbsolutePath() + "/aaa.pdf");
byte[] data = Base64.decode(evrakIcerikB64, 0);
boolean exec=myDir.setExecutable(true);
boolean read=myDir.setReadable(true);
boolean wri=myDir.setWritable(true);
how can i change file permission?
Related
I am trying to get the path of my app's sqlite db file as I want to backup it to Google drive in app, but it gives me a different path:
String Path = getApplicationContext().getDatabasePath("mydb.db").getAbsolutePath();
File filePath = new File(Path);
This Path gives me: /data/user/0/mypackage/databases/mydb.db
But when I use:
File data = Environment.getDataDirectory();
String Path ="/data/mypackage/databases/mydb.db";
File filePath = new File(data,Path);
So the final path is /data/data/mypackage/databases/mydb.db and with this path the backup is also working.
I can also see the db file there in the file browser in android studio when the device is attached.
So why the getDatabasePath gives me path like data/user/0/ ?
I am trying to access a file in Processing Android Mode using the following:
File file = new File(filePath);
And I tried the following options for setting filePath for the file “1.sf2” in the “data” folder that I created in the current sketch directory. However, none of them worked.
filePath = dataPath(“1.sf2”);
filePath = sketchPath(“data/1.sf2”);
filePath = sketchPath(“assets/1.sf2”);
filePath = “data/1.sf2”;
filePath = “assets/1.sf2”;
According to the github page of Processing Android Mode, everying file in the “data” folder of the current sketch directory are automatically copied to the “assets” folder of the generated apk file. However, I keep getting “java.io.FileNotFoundException: /null/restore_pixels: open failed: ENOENT (No such file or directory)” exception every time I run the application on my Android device.
Is there a way to correctly access a file in Processing Android Mode? Thanks a lot!
My device has no SD card, but I can access the files of "Internal storage" in Windows explorer, in which there is a "tmp.txt".
The txt file was pasted via Windows explorer, now I want to read this file. My codes are:
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"tmp.txt");
StringBuilder text = new StringBuilder();
try {
InputStream in = new FileInputStream(file);
...
}
catch (IOException e) {
}
But it's not working, it step to catch exception after new FileInputStream(file);, the debug information logs the file location actually is "/storage/emulated/0/tmp.txt", so it couldn't find the file.
Then I tried put the file in the Download directory using:
File fileDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File file = new File(fileDir, "tmp.txt");
error log:exception e:
It's not working either, basically they are the same problem. Can I access files in this directory?
Read this: developer.android.com/guide/topics/data/data-storage You don't have the permission to read the storage, the permissions you put are for location services.
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?
I want load a file wav from sdcard in my android project but I don't succeed.
I'm using
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"/mnt/sdcard/.....wav");
but I get this error
java.io.FileNotFoundException: /mnt/sdcard/mnt/sdcard/......wav (No such file or directory)
Can you help me, please?
the first parameter is already the path - do not put /mnt/sdcard/ to the second parameter
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,".....wav");
Remove this /mnt/sdcard/ from the line It is already there in file
Replace this:
File file = new File(sdcard,"/mnt/sdcard/.....wav");
with this:
File file = new File(sdcard,".....wav");