Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8944981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:08:36+00:00 2026-06-15T12:08:36+00:00

I need to be able to save a file to the external storgage temp

  • 0

I need to be able to save a file to the external storgage temp dir. The file I am saving though is the R.raw directory of my app.

I have used this example here.
Move Raw file to SD card in Android

The issue is
1. The app seems to read the .m4a file I want (possible reads the bytes wrong here).
2. When the file is saved to the /tmp dir the file size is totally wrong.
eg one file goes from 30kb to 300kb, another goes from 25kb, to .25kb.

Any suggestions

public String saveAs(int ressound, String whipName){  

     byte[] buffer=null;  
     InputStream fIn = getBaseContext().getResources().openRawResource(ressound);  
     int size=0;  

     try {  
      size = fIn.available();  
      buffer = new byte[size];  
      fIn.read(buffer);  
      fIn.close();  
     } catch (IOException e) {  
      // TODO Auto-generated catch block
         Log.i("saveas", "did not save1");
      //return false;  
     }  

     String path= Environment.getExternalStorageDirectory().getAbsolutePath()+"/tmp/.pw2";
     String filename="/"+whipName+".m4a";  
     Log.i("path", "file path is " + path);
     boolean exists = (new File(path)).exists();  
     if (!exists){new File(path).mkdirs();}  

     FileOutputStream save;  
     try {  
      save = new FileOutputStream(path+filename);  
      save.write(buffer);  
      save.flush();  
      save.close();  
     } catch (FileNotFoundException e) {  
      // TODO Auto-generated catch block  
         Log.i("saveas", "did not save2");
         //return false;  
     } catch (IOException e) {  
      // TODO Auto-generated catch block
         Log.i("saveas", "did not save3");
      //return false;  
     }      

     File k = new File(path, filename);  

     return  k.getAbsolutePath();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:08:37+00:00Added an answer on June 15, 2026 at 12:08 pm

    You CAN read a file in one full buffer like you’re doing, but this is generally bad practice, unless you know the files are small, and the InputStream will know the full size in advance and be able to load all data at once.

    If you aren’t absolutely sure of max file size, especially on mobile, don’t try to load the full thing in memory.

    See IOUtils code for the classic example:

    http://grepcode.com/file/repo1.maven.org/maven2/commons-io/commons-io/1.4/org/apache/commons/io/IOUtils.java#IOUtils.copyLarge%28java.io.InputStream%2Cjava.io.OutputStream%29

    public static long copyLarge(InputStream input, OutputStream output)
            throws IOException {
        byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
        long count = 0;
        int n = 0;
        while (-1 != (n = input.read(buffer))) {
            output.write(buffer, 0, n);
            count += n;
        }
        return count;
    }
    

    Also, make sure to close your buffers explicitly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using: https://github.com/blueimp/jQuery-File-Upload Basically, I need to be able to save the current done
I have to be able to save a file, unfortunatly it can potentially be
I need to be able to save the main window of a pyqt app
Need to be able to pull Magento products into an external template. Need to
I need to be able to create an id for a hyperlink. I have
I need to be able to send a file to another website from server-side
I need to Pass some data to a text file and save that text
I need the user of my Flex application to be able to save a
I need to save the Email Message on the disk as an .msg file,
I have an application that creates an audio file. I need to provide a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.