Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android中创建临时文件_Android - Fatal编程技术网

在android中创建临时文件

在android中创建临时文件,android,Android,在我的android应用程序中,我试图使用create temp创建一个音乐文件,并尝试读取该文件。现在我能够创建,但它给出了一个错误,表示无法播放视频 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); //File newfile=new Fil

在我的android应用程序中,我试图使用create temp创建一个音乐文件,并尝试读取该文件。现在我能够创建,但它给出了一个错误,表示无法播放视频

    public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);  
   //File newfile=new File("/data/data/com.ayansys.samplevideo/Music.3gp");

    //String xyz=newfile.getAbsolutePath();
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); // Sets the window in full screen
    setContentView(R.layout.main);
   // path.g
   // Log.i("Raw folder path:", R.raw.music);
   String path= musicFile();
    try{
    Thread.sleep(5000);
    }
    catch(InterruptedException e)
    {
        e.printStackTrace();
        Log.i("exception raised",e.toString());
    }
    mVideoView = (VideoView) findViewById(R.id.surface_view);
    // mVideoView.setVideoURI(Uri.parse("android.resource://com.ayansys.samplevideo/"+R.raw.music));

   // File infile=new File("/data/data/com.ayansys.samplevideo/Video.3gp");
    mVideoView.setVideoPath(path);

    mVideoView.requestFocus();
    mVideoView.start();

}

public   String  musicFile()
{
    String temPath = null;
    try{
        File outFile=File.createTempFile("music", ".3gp", getDir(temPath, MODE_PRIVATE));
        temPath=outFile.getAbsolutePath();
        FileOutputStream f=new FileOutputStream(outFile);
        //FileOutputStream fos = openFileOutput("music.3gp", Context.MODE_PRIVATE);
        URL u = new URL("http://59.162.166.211/aptv-web/VODAFONE/STARONE/SarabhaivsSarabhai/J2ME/SarabhaivsSarabhai_05.3gp");
    HttpURLConnection c = (HttpURLConnection) u.openConnection();
    c.setRequestMethod("GET");
    c.setDoOutput(true);
    c.connect();
    //FileOutputStream f = new FileOutputStream(new File("/sdcard/videooutput.mp4"));


    InputStream in = c.getInputStream();

    byte[] buffer = new byte[1024];
    int len1 = 0;
    while ( (len1 = in.read(buffer))!= -1 ) {
         f.write(buffer,0,len1);
    }

    f.close();
    String str=outFile.getAbsolutePath();
    //outFile..close();
    in.close();

}
    catch(Exception e)
    {
        e.printStackTrace();
        System.out.println("Exception raised in creating a file: "+e.toString());
    }
    return temPath;
}
}

我想玩这个。 请分享你的宝贵建议


提前感谢

上下文。openFileOutput(字符串名称,int模式)在内部存储器上打开一个文件


我建议您阅读,因为它涵盖了内部和外部存储问题。

Context.openFileOutput(字符串名称,int模式)
在内部存储上打开一个文件


我建议您阅读,因为它涵盖了内部和外部存储问题。

这个问题以前已经解决过。[stackoverflow][1][1]:此问题以前已解决。[stackoverflow][1][1]: