小问题在DDMS数据文件夹
我是新来的机器人。所以我想实现一个code存储在设备的内部存储的数据。它被存储和加载数据。我看不到这是present在eclipse中的数据文件夹中的文件。当我点击的数据文件夹,它没有扩大。
I am new to android . So i was trying to implement a code which stores the data in the internal storage of the device. It is storing and loading the data. I cannot see the file in the data folder which is present in the eclipse. When i click the data folder , it is not expanding.
我用下面code
package com.example.files;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
EditText textBox;
static final int READ_BLOCK_SIZE = 100;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textBox = (EditText) findViewById(R.id.txtText1);
}
public void onClickSave(View view){
String str = textBox.getText().toString();
try
{
FileOutputStream fOut =
openFileOutput("textfile.txt",
MODE_WORLD_READABLE);
OutputStreamWriter osw = new
OutputStreamWriter(fOut);
//---write the string to the file---
osw.write(str);
osw.flush();
osw.close();
//---display file saved message---
Toast.makeText(getBaseContext(),
"File saved successfully!",
Toast.LENGTH_SHORT).show();
//---clears the EditText---
textBox.setText("");
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
public void onClickLoad(View view) {
try
{
FileInputStream fIn =
openFileInput("textfile.txt");
InputStreamReader isr = new
InputStreamReader(fIn);
char[] inputBuffer = new char[READ_BLOCK_SIZE];
String s = "";
int charRead;
while ((charRead = isr.read(inputBuffer))>0)
{
//---convert the chars to a String---
String readString =
String.copyValueOf(inputBuffer, 0,
charRead);
s += readString;
inputBuffer = new char[READ_BLOCK_SIZE];
}
//---set the EditText to the text that has been
// read---
textBox.setText(s);
Toast.makeText(getBaseContext(),
"File loaded successfully!",
Toast.LENGTH_SHORT).show();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
的数据文件夹是该装置的内部存储器的一部分,并且不应该被访问过DDMS为设备
The data folder is part of the internal storage of the device and should not be accessible over DDMS for a device.
但是,您可以在模拟器中运行你的应用程序,然后你可以浏览仿真器的数据目录中DDMS。
You can however run your app on the emulator and then you can browse the emulator's data directory in DDMS.
在沙盒的概念,全新的智能手机操作系统的工作中的应用程序。如果机器人的一个应用程序沙箱目录是/数据/数据/ your_app_package /
The apps in all new smartphone OS's work on the concept of sandboxing. In case of Android the sandbox directory for an app is /data/data/your_app_package/
此目录中的文件和目录,默认情况下只提供给应用程序。如果你想查看使用DDMS的设备上的文件,我建议你使用getExternalStorage()和复制/移动文件没有得到外部存储的句柄。默认保存位置的应用程序文件是getFilesDir(),它/数据/数据/ your_app_package /文件
The files and directories in this directory are by default only available to the app. If you want to view the files using DDMS on a device, I suggest you get a handle on the External Storage using getExternalStorage() and copy/move your files there. The default location to save your files in the app is getFilesDir() which /data/data/your_app_package/files