android在當前app該文件下創建一個文件夾


/*********************************************************************  * Author  : Samson  * Date    : 04/22/2014  * Test platform:  *              3.11.0-12-generic #19-Ubuntu  *              GNU bash, version 4.2.45  * *******************************************************************/
package com.example.listfile;

import java.io.File;   
import java.io.IOException;   
 
import android.app.Activity;   
import android.content.Context;
import android.widget.TextView;
import android.os.Bundle;     
import android.os.Process;

public class MainActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        int myProcessID = Process.myPid();
        File yygypath = this.getFilesDir();//this.getCacheDir();
        String yygypathstr = yygypath.toString();
        File file = new File(yygypath, "yygytest"); 
        try {
			file.createNewFile();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        yygypathstr = yygypathstr + " pid is " + myProcessID;
        
        TextView  tv = new TextView(this);
        tv.setText(yygypathstr);
        setContentView(tv);
    }
    public void onDestory()
    {
    	super.onDestroy();
    	this.finish();
    	android.os.Process.killProcess(android.os.Process.myPid());
    	System.exit(0);    	
    }
}

主要是這兩個函數:
this.getFilesDir(); 這個是得到當前app文件夾下的files文件夾路徑
this.getCacheDir(); 這個是得到當前app文件夾下的cache文件夾路徑

 結果:
adb shell result:
 root@generic:/data/data/com.example.listfile/files # ll                        
-rw------- u0_a53   u0_a53          0 2014-04-21 13:38 yygytest
root@generic:/data/data/com.example.listfile/files # 

版權聲明:本文博客原創文章,博客,未經同意,不得轉載。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM