gpt4 book ai didi

android - 文件夹创建为文件

转载 作者:行者123 更新时间:2023-11-29 21:50:34 25 4
gpt4 key购买 nike

CONFUSED:那些对问题投反对票的人,你能添加一些评论吗,为什么????想说脏话,只是不想被封号。

我有一个应用程序,我想在 sdCard 中有一个文件夹,以便用户可以添加一些东西,然后我可以在应用程序中使用它。我使用以下代码创建一个文件夹:

    @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//External storage
boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {
// We can read and write the media
mExternalStorageAvailable = mExternalStorageWriteable = true;
Log.v("Storage","ablo to read and write");
//create Beatss folder
File direct = new File(android.os.Environment.getExternalStorageDirectory().getPath() + "/Beatss");
Log.v("Storage",android.os.Environment.getExternalStorageDirectory().getPath() + "/Beatss");
boolean success = true;
if (!direct.exists()) {
success = direct.mkdirs();

}
if (success) {
// Do something on success
Log.v("Storage","Folder has been created");

} else {
// Do something else on failure

}

} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
// We can only read the media
mExternalStorageAvailable = true;
mExternalStorageWriteable = false;
Log.v("Storage","ablo to read only");
} else {

mExternalStorageAvailable = mExternalStorageWriteable = false;
Log.v("Storage","no access");
}

我可以在 DDMS 中看到该文件夹​​已创建,但是当我通过 WindowsExplorer 时,我有一个文件而不是文件夹。那么,如何创建文件夹呢?

UPD1:所以,即使我在这个文件夹中创建了一些东西,我仍然把它作为一个文件放在 Windows 资源管理器中,但是在 DDMS 中我可以看到我有一个文件夹,里面还有另一个文件夹。那么,这里有什么问题?

UPD2:因此,分解 logcat 中的 direct 行以查看是否存在真实路径:

01-24 21:14:04.368: V/Storage(12116): /mnt/sdcard/Beatss/

所以有..

UPD3:我无法显示我所有的代码,到目前为止是 264 行。所有这些文件夹的创建都发生在 mainActivity 的 onCreate 中。 list 文件如下所示:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.test
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto" >

<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="16" />
<supports-screens
android:smallScreens= "true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="false"
/>


<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:screenOrientation="portrait"
>
<activity
android:name=".Main"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity android:name=".SupportScreen"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity android:name="com.tapjoy.TJCOffersWebView" android:configChanges="keyboardHidden|orientation" />
<activity android:name="com.tapjoy.TapjoyFullScreenAdWebView" android:configChanges="keyboardHidden|orientation" />
<activity android:name="com.tapjoy.TapjoyDailyRewardAdWebView" android:configChanges="keyboardHidden|orientation" />
<activity android:name="com.tapjoy.TapjoyVideoView" android:configChanges="keyboardHidden|orientation" />

</application>
</manifest>

更新上层代码:

Logcat 说:

01-24 21:19:21.068: V/Storage(14088): /mnt/sdcard/Beatss/
01-24 21:19:21.138: V/Storage(14088): Folder has been created

最佳答案

尝试一下

String PATH = Environment.getExternalStorageDirectory()+"/Folder123/";
File file = new File(PATH);
file.mkdirs();

关于android - 文件夹创建为文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14505371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com