简体   繁体   中英

FileInputStream fis.read() gives exception

I want to gain access to SD-CARD for this i am write some code :

File f=Environment.getExternalStorageDirectory().getAbsolutePath();

//   f=/mnt/sdcard 

byte[] bytearray=new byte[4];

FileInputStream fis=new FileInputStream(f);

fis.read(bytearray,1,1);   //This line gives exception

I can't figure out why this an exception

What you are trying to read is not actually a file, but a directory.

This is the reason why you are getting an exception.

For listing de directectory contents, you should use the list() method on the File object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM