public class MainActivity extends Activity {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView1);
File div = new File(Environment.getExternalStorageDirectory(),
"MyTestFile/Hello");
if (!div.exists()) {
div.mkdirs();
textView.setText("檔案已新增");
}
else
{
textView.setText("檔案已存在");
}
}
}
記得一定要新增權限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
歡迎轉載,請註明出處。
沒有留言:
張貼留言