Keep receiving file no error exists (even with existing directory)

I am trying to use a simple FileReader and still Android Studio keeps telling me that this file does not exist. I am using Apache POI if it matters; no matter what directory I am using is 100% correct and I have hidden extensions enabled so this is not a problem.

Any help would be appreciated,

Jacob

My java (where ncaa.xlsx exists):

  FileInputStream file = new FileInputStream(new File("C:\\AdwCleaner\\ncaa.xlsx"));

      

+3


source to share


3 answers


An Android app runs on a virtual or physical device that has a completely separate file system.

There are several ways to transfer a file to your device.

For example, you can push a file to the device using adb push

or using the file explorer in DDMS.

If you copy the file to a folder on your SD card, you can open it with Environment.getExternalStorageDirectory()

(see example here ):



File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard, "<path to your file>");

      

You can also put the file in the assets folder, so it will be automatically available on the device (see this to create the folder and this to read the file from it):

InputStream file_stream = getAssets().open("myfile.xslx")

      

+1


source


Maybe it's an antivirus? Maybe try temporarily disabling your antivirus scanner (with your network connection disabled) and restarting your Java application.



0


source


You cannot open a file that exists on the PC file system on an Android device.

You need to first push it either with the command line command adb push

or with the DDM DDM function.

After that, you can use the Android API to open the file. For example:

Environment.getExternalStorageDirectory()
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard, "file path");

      

0


source







All Articles