package com.panpass.main;
import java.io.File;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.TextView;
import com.example.testtwo.R;
public class MainActivity extends Activity {
private String strPath;
private String rootPath;
private String parentFilePath;
private TextView mShowPath;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
mShowPath = (TextView) findViewById(R.id.text_view_path);
rootPath = Environment.getExternalStorageDirectory().getPath()+File.separator;
String str1 = Environment.getDataDirectory().getPath(); // /data
String str2 = Environment.getDownloadCacheDirectory().getPath(); // /cache
String str3 = Environment.getRootDirectory().getPath(); // /system
mShowPath.setText(str1+"\n"+str2+"\n"+str3);
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
strPath = rootPath+"mycachetest"+File.separator+"fuck.txt";
parentFilePath = rootPath+"mycha";
File parentFile = new File(parentFilePath);
if(!parentFile.exists()){
parentFile.mkdirs();
}
File destFile = new File(parentFile,"fuck.txt");
if(!destFile.exists()){
destFile.getParentFile().mkdirs();
try {
destFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
mShowPath.setText(destFile.getAbsolutePath());
}
}
}
}
======CreateFile======
最新推荐文章于 2022-07-29 21:34:00 发布