• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to upload a word document using emulator to store local folder?

karthik964

Lurker
Hi !
I am new in android development. Please any one reply.
How to upload a word document and store to emulator device and sent to web api server.
 
A couple of questions: Where are you trying to upload this document from and to? And how are you trying to open the document?
 
I Find the solution now. It is working.

Code:
    protected void onActivityResult(int req, int result, Intent data)
    {
        // TODO Auto-generated method stub
        super.onActivityResult(req, result, data);
        if (result == RESULT_OK)
        {
        Uri fileuri = data.getData();
         String sourcefileType = getContext().getContentResolver().getType(fileuri);
        InputStream inputStream = getContext().getContentResolver().openInputStream(fileuri);
        String fileNamePath="/storage/emulated/0/data/tempfile/12230170801_163209.docx";
        File mediaFile = new File(fileNamePath);
        FileOutputStream fileOutputStream = null;
        int count = 0;
        long ll = mediaFile.length();
        byte[] buffer = new byte[1024];         // please confirm the automatically get file size
        while ((count = inputStream.read(buffer)) > 0) {
            fileOutputStream.write(buffer, 0, count);
        }
        if (fileOutputStream != null) {
            fileOutputStream.close();
        }
    }
}
 
Last edited by a moderator:
How to set any size of file to upload? The above code is working, this is correct or not?
byte[] buffer = new byte[1024]; // please confirm the automatically get file size
 
How are you not getting a NullPointerException at line 18?
 
Back
Top Bottom