问题
Is there any way to save a text file created from an android app to a USB connected windows PC programmatically?
回答1:
No, sorry. Android devices have no access to their host PC via USB cable.
回答2:
Short answer - not that I know of.
For "file transfer" in general, I would definitely look at both Dropbox (save/synch anything to anything, anywhere) and ESFileExplorer. Both are user-oriented, but Dropbox has an API that you should be able to use with Android (I haven't tried it). ESFileExplorer works with both USB and Windows shares.
If you have the Android SDK, you can copy files from the command line with "adb pull". And of course you can invoke "adb pull" from Java with "Runtime.exec()". Ugly ... but do-able :)
One other possibility for Windows shares might be:
a) Get an SMB client (for example, Samba Filesharing), then
b) Use standard Java IO to read and write to and from the share
Again, I haven't tried this ... and I don't know if it would work ... but it might be worth a shot. I don't see anything in Android File I/O that appears fundamentally incompatible with Samba file sharing:
- http://developer.android.com/reference/java/io/File.html
回答3:
Try using adb pull
command from your PC to fetch the file from Android. You will need to install the Android SDK and have a usb cable (although there are ways to do it wirelessly).
回答4:
You cannot write a file from an Android device to a PC by Android programming. However, you can copy a file from Android device by Windows programming (C#). You can get help from windows device portable library: https://github.com/notpod/wpd-lib
来源:https://stackoverflow.com/questions/12608893/save-file-from-android-device-to-windows-programmatically