问题
Through my Android program I wrote a file like this:
String file = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Files/hello.txt";
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(str+"\n"); \\yeah string has a value there
writer.close();
Now when I go to Android's "Astro" File browser, I can see the file hello.txt in /mnt/sdcard/Files
but when I mount the sdcard in Windows, I can only see 4 other files which were there in that folder but not hello.txt.
In Windows itself, I even tried to uncheck the hide hidden files option just to ensure that the file is not hidden but it's just not visible.
I even tried to write the file in root of the sdcard but again same problem. Now I'm surprised that how is it possible that I can see the file in Android but not in Windows. In Android I've even checked the file contents and everything looks fine.
What could be the problem? Is the way I'm writing the file wrong?
PS: yes the Manifest permission android.permission.WRITE_EXTERNAL_STORAGE
is added.
回答1:
Ok, I figured out why it was happening.
Actually even if we press "Back" button, the program keeps running and unless I go to Settings > Applications > Manage Applications > "Force Stop" <application>
I can't access the file written by this program even if it is on sd card and even if the filewriter has been closed.
This is just based on my observation and I'd like someone to post a better answer with facts and with solution.
edit: I'll update my question accordingly.
edit: as recommended on meta I've posted a new question
Can't see a file in Windows written by an android app on sd-card unless I “Force Close” the app
回答2:
If worse comes to worst disconnect, reboot and reconnect your Android device. The files should show up then.
回答3:
I have found a workaround.
I wrote a routine to capture data from the phone accelerometer. I noticed if the file had a .dat or .txt extension I could not see it and could not copy it to my PC.
By not assigning a file extension to the file on the Android side, I found it would be visible from the PC. After copying it to the PC and adding a .txt extension, it could then be viewed on the PC.
回答4:
To display hidden files and folders
- Open Folder Options in Control Panel
- Click Start, and then click Control Panel.
- Click Appearance and Themes, and then click Folder Options.
- On the View tab, under Hidden files and folders, click Show hidden files and folders.
来源:https://stackoverflow.com/questions/7391432/unable-to-see-file-in-windows-explorer-while-it-is-visible-in-android-file-brows