android-file

Create and Share a File from Internal Storage

送分小仙女□ 提交于 2019-11-26 15:22:47
My goal is to create a XML file on internal storage and then send it through the share Intent. I'm able to create a XML file using this code FileOutputStream outputStream = context.openFileOutput(fileName, Context.MODE_WORLD_READABLE); PrintStream printStream = new PrintStream(outputStream); String xml = this.writeXml(); // get XML here printStream.println(xml); printStream.close(); I'm stuck trying to retrieve a Uri to the output file in order to share it. I first tried to access the file by converting the file to a Uri File outFile = context.getFileStreamPath(fileName); return Uri.fromFile

Android, how do can I get a list of all files in a folder?

自作多情 提交于 2019-11-26 13:03:29
问题 I need the name (String) of all files in res/raw/ I tried: File f = new File(\"/\"); String[] someFiles = f.list(); It looks like the root directory is the root of the android emulator...and not my computers root directory. That makes enough sense, but doesn\'t really help me find out where the raw folder exists. Update: Thanks for all the great replies. It appears that some of these are working, but only getting me half way. Perhaps a more detailed description will aid I want to get all the

Writing Text File to SD Card fails

杀马特。学长 韩版系。学妹 提交于 2019-11-26 11:18:59
问题 I have a strange problem I\'ve come across. My app can write a simple textfile to the SD Card and sometimes it works for some people but not for others and I have no idea why. For some people, it force closes if they put some characters like ... in the File and such. I cannot seem to reproduce it as I\'ve had no troubles but this is the code which handles the File writing. Can anyone think of something that may lead to problems or a better to way to do it? public void generateNoteOnSD(String

Trying to create a file in Android: open failed: EROFS (Read-only file system)

不想你离开。 提交于 2019-11-26 07:37:57
问题 This line: final FileOutputStream outputStream = new FileOutputStream(name); results in a FileNotFoundException with the message being /2ozjfFQzwv: open failed: EROFS (Read-only file system) where \"2ozjfFQzwv\" is what I passed as the name of the file. I have tried this with and without the WRITE_INTERNAL_STORAGE permission. How do I create this file for writing? Alternatively, I just want to be able to give an image to a new activity, and it is too large to serialize it in an extra. Is

List all the files from all the folder in a single list

試著忘記壹切 提交于 2019-11-26 07:25:27
问题 Hi I am looking for the solution to list all the files from root/Android device. Suppose there are 3 folder inside root directory,but I want to display all the files in all of these folder in a single list.. Now If am using File f=new File(\"/sdcard\"); Then it will list all the files from the sdcard folder only..and If I will use File f=new File(\"/download\"); Then it will list all the files from download folder only ..and if I will use File f=new File(\"/\"); Then it will list only root

Create and Share a File from Internal Storage

落花浮王杯 提交于 2019-11-26 04:24:34
问题 My goal is to create a XML file on internal storage and then send it through the share Intent. I\'m able to create a XML file using this code FileOutputStream outputStream = context.openFileOutput(fileName, Context.MODE_WORLD_READABLE); PrintStream printStream = new PrintStream(outputStream); String xml = this.writeXml(); // get XML here printStream.println(xml); printStream.close(); I\'m stuck trying to retrieve a Uri to the output file in order to share it. I first tried to access the file

How to create directory automatically on SD card

核能气质少年 提交于 2019-11-26 01:48:31
问题 I\'m trying to save my file to the following location FileOutputStream fos = new FileOutputStream(\"/sdcard/Wallpaper/\"+fileName); but I\'m getting the exception java.io.FileNotFoundException However, when I put the path as \"/sdcard/\" it works. Now I\'m assuming that I\'m not able to create directory automatically this way. Can someone suggest how to create a directory and sub-directory using code? 回答1: If you create a File object that wraps the top-level directory you can call it's mkdirs

android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData()

拥有回忆 提交于 2019-11-26 01:17:55
问题 The app is crashing when I\'m trying to open a file. It works below Android Nougat, but on Android Nougat it crashes. It only crashes when I try to open a file from the SD card, not from the system partition. Some permission problem? Sample code: File file = new File(\"/storage/emulated/0/test.txt\"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), \"text/*\"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); // Crashes on this

Show Image View from file path?

三世轮回 提交于 2019-11-26 00:17:22
问题 I need to show an image by using the file name only, not from the resource id. ImageView imgView = new ImageView(this); imgView.setBackgroundResource(R.drawable.img1); I have the image img1 in the drawable folder. I wish to show that image from the file. How can I do this? 回答1: Labeeb is right about why you need to set image using path if your resources are already laying inside the resource folder , This kind of path is needed only when your images are stored in SD-Card . And try the below

How to create directory automatically on SD card

北慕城南 提交于 2019-11-25 23:34:03
I'm trying to save my file to the following location FileOutputStream fos = new FileOutputStream("/sdcard/Wallpaper/"+fileName); but I'm getting the exception java.io.FileNotFoundException However, when I put the path as "/sdcard/" it works. Now I'm assuming that I'm not able to create directory automatically this way. Can someone suggest how to create a directory and sub-directory using code? If you create a File object that wraps the top-level directory you can call it's mkdirs() method to build all the needed directories. Something like: // create a File object for the parent directory File