Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android where file is saved FileOutputStream

Tags:

file

android

save

Here how I write bytes to a file. I'm using FileOutputStream

    private final Handler handler = new Handler(){
            @Override
            public void handleMessage(Message msg) {
                FragmentActivity activity = getActivity();
                        byte[] readBuffer = (byte[]) msg.obj;
                        FileOutputStream out = null;
                        try {
                            out = new FileOutputStream("myFile.xml");
                            out.write(readBuffer);
                            out.close();
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
           }
}

and now I want to open that file, so I need to have path of that file. So how I need to open that file?

EDIT:

Here how I read from file, but I can't see anything...

BufferedReader reader = null;
                    FileInputStream s = null;
                    try {
                        s = new FileInputStream("mano.xml");
                        reader = new BufferedReader(new InputStreamReader(s));

                        String line = reader.readLine();
                        Log.d(getTag(), line);
                        while (line != null) {
                            Log.d(getTag(), line);
                            line = reader.readLine();
                        }
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
like image 510
David Avatar asked Sep 28 '22 04:09

David


1 Answers

I recommend to use this for writting:

OutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath()+"/yourfilename");

So to read the location:

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+transaction.getUniqueId()+".pdf");

To read the path:

file.getAbsolutePath();
like image 171
Victor Martínez Avatar answered Oct 13 '22 02:10

Victor Martínez