文件路径操作
package com.sdcard;
import java.io.File;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.TextView;
public class SDCardActivity extends Activity {
/** Called when the activity is first created. */
private TextView tvShow;
/*private final String SDRoot = Environment.getExternalStorageDirectory().getPath() + "/";
private final String MP3FeiFanPath = SDRoot + "feifan";
private final String MP3SongPath = MP3FeiFanPath + "/song" ;
private final String MP3LrcPath = MP3FeiFanPath + "/lrc";*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tvShow = (TextView)this.findViewById(R.id.tvShow);
// tvShow.setText(SDRoot);
createMp3Dir(Mp3Paths.MP3SongPath);
createMp3Dir(Mp3Paths.MP3LrcPath);
}
//创建路径
private boolean createMp3Dir(String path) {
if(path == null || path.trim().length() == 0){
return false;
}
File file = new File(path);
boolean b = false;
if(!file.exists() || !file.isDirectory()){
b = file.mkdirs();
System.out.println(b);
}
return false;
}
}
路径设置
package com.sdcard;
import android.os.Environment;
/**
* 下载好的Mp3音乐在手机中的路径
* @author: Cody_408516
* @Date: Mar 30, 2011
*/
public class Mp3Paths {
public static final String SDRoot = Environment.getExternalStorageDirectory().getPath() + "/";
public static final String MP3FeiFanPath = SDRoot + "feifan";
public static final String MP3SongPath = MP3FeiFanPath + "/song" ;
public static final String MP3LrcPath = MP3FeiFanPath + "/lrc";
}
权限设置
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>