Click here to Skip to main content
15,881,599 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

In my app, I have added a new directory to assets. This directory has one binary (.bin)file.
I'm trying to read this file using InputStream with no success.
I can see the file name I even can compare the name to an existing string, but I can't open it.

Please advise.

What I have tried:

Java
AssetManager manager =SmartControlApplication.getContext().getResources().getAssets();
	String[] list = null;
        try{
            list = manager.list("firmware");
            for(String file : list){
                if(file.toString().equals(imgPath)){ //return true, the file does exist
                    Log.d(LOG_TAG, "file name "+ file.toString());
                    InputStream stream = manager.open(file);
                    stream.read(mFileBuffer, 0, mFileBuffer.length);
                    stream.close();  
                    success = true;
                }
            }
        }catch(IOException ex){
            ex.printStackTrace();
            success = false;
        }

I also tried to use BufferReader
Java
BufferedReader reader = null;
reader = new BufferedReader(new InputStreamReader(manager.open(file)));
String mLine;
while ((mLine = reader.readLine()) != null) {
//process line
Log.d(LOG_TAG, "file name "+ file.toString());

But always InputStream sees no file.
Posted
Updated 5-Apr-18 4:39am
Comments
wseng 29-Mar-18 12:01pm    
Did it displayed something in this line ? Log.d(LOG_TAG, "file name "+ file.toString());
Samira Radwan 29-Mar-18 12:12pm    
Yes, it does. I have just checked the Logcat
wseng 29-Mar-18 12:18pm    
check which line is wrong. Maybe it fail after InputStream stream = manager.open(file); ?
Samira Radwan 29-Mar-18 12:21pm    
It fails at this line. InputStream doesn't see the file when i try to open it. I even used DataInputStream and it gives the same (No such file or directory). any suggestions?
wseng 29-Mar-18 12:24pm    
Can you replace to this code and see ? InputStream inputStream = new FileInputStream(inputFile);

1 solution

I suspect you want something like:
InputStream stream = manager.open("firmware/" + file);
 
Share this answer
 
Comments
Samira Radwan 5-Apr-18 16:21pm    
Looks like you might be right. I will give it a try. thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900