A J
A J

Reputation: 4652

save and upload a file from internal memory

save and upload a file from internal memory in android

I had try to save a file into internal memory

String smsXml = "<messages><sms><From>" + address + "</From><Date>" + finalDateString + "</Date><Body>" + msg +"</Body></sms></messages>";

            try {
                //saving the file as a xml
                FileOutputStream fOut = openFileOutput("textMessage.xml",MODE_WORLD_READABLE);
                OutputStreamWriter osw = new OutputStreamWriter(fOut);
                osw.write(smsXml);
                osw.flush();
                osw.close();
            }
            catch (Throwable e) {
                Log.d("Exception","Exception:"+ e);
            } 

Now I try to upload the file to server But how can I get file path to upload this.I had successfully uploaded a .mp3 from sd card but how to do that from internal memory.Follow this link for uploading .mp3

final String uploadFilePath = "android/data/data/com.example.sms/files/";
final String uploadFileName = "textMessage.xml";

Upvotes: 0

Views: 1093

Answers (1)

Timu&#231;in
Timu&#231;in

Reputation: 4673

Use getFileStreamPath(). This will return the file created by openFileOutput method in Files directory.

File file = getFileStreamPath("textMessage.xml");

Then you can get the path String with getPath method:

String path = file.getPath();

Upvotes: 1

Related Questions