更新时间:2023-10-22 19:44:40
文件存储在到/ mnt / SD卡/(外部存储)或/数据/数据/你的包名/(内部存储)(如在这个问题)。你可以从这个包只(除非手机是植根)访问此文件夹。
你问题的第二部分是不是很清楚。从我能理解,Android是不一样的Windows(没有桌面文件夹)。要在桌面上创建一个快捷方式,你需要实现一个App部件。
I am working on a small program on Android to write some hard-coded text to a file with a hard-coded name. While the operation is successful (there are no errors), I am not able to find the file on the emulator. My questions:
The code:
public class MainActivity extends Activity {
Button writeFile;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
writeFile = (Button) findViewById(R.id.writeFile);
writeFile.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Step 1. Get file name.
String file = "hello_files.txt";
String str = "hello world";
Log.v(this.toString(), "Going to write to a file.");
FileOutputStream fos;
try {
fos = openFileOutput(file, MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE);
fos.write(str.getBytes());
Log.v(this.toString(), "Local path = ");
fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
Log.v(this.toString(), "File not found!!");
e.printStackTrace();
} catch (IOException e) {
Log.v(this.toString(), "IO Exception.");
e.printStackTrace();
}
}
});
}
Files are stored in "/mnt/sdcard/" (External storage) or "/data/data/Your Package Name/" (Internal storage) (as in this question). You can access this folder from this package only (unless the phone is rooted).
The second part of your question is not very clear. From what I can understand, Android is not like Windows (no desktop folder). To create a shortcut on the desktop, you need to implement an App widget.