android拷贝文件到内部存储,将文件保存在内部存储android中
我是Android的新手,当我尝试将文件保存到内部存储器时,我遇到了问题,新的示例适用于我的sdk,但不适用于我的手机.我正试图在一个索尼爱立信xperia中运行de示例,顺便说一下android 2.1 ... log.i- 给了我下一行:/data/data/com.example.key/files/text/(my_title)谢谢.@Overrideprotected void on..
我是Android的新手,当我尝试将文件保存到内部存储器时,我遇到了问题,新的示例适用于我的sdk,但不适用于我的手机.
我正试图在一个索尼爱立信xperia中运行de示例,顺便说一下android 2.1 ... log.i - 给了我下一行:
/data/data/com.example.key/files/text/(my_title)
谢谢.
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.new_text);
file = (EditText) findViewById(R.id.title_new);
entry = (EditText) findViewById(R.id.entry_new);
btn = (Button) findViewById(R.id.save_new);
btn.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v) {
File myDir = getFilesDir();
NEWFILENAME = file.getText().toString();
if (NEWFILENAME.contentEquals("")){
NEWFILENAME = "UNTITLED";
}
NEWENTRY = entry.getText().toString();
try {
File file_new = new File(myDir+"/text/", NEWFILENAME);
file_new.createNewFile();
Log.i("file", file_new.toString());
if (file_new.mkdirs()) {
FileOutputStream fos = new FileOutputStream(file_new);
fos.write(NEWENTRY.getBytes());
fos.flush();
fos.close();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent textPass = new Intent("com.example.TEXTMENU");
startActivity(textPass);
}
});
}
//That's for creating... then in other activity i'm reading
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.text_menu);
btn = (Button) findViewById(R.id.newNote);
listfinal = (ListView) findViewById(R.id.listView);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent textPass = new Intent("com.example.TEXTNEW");
startActivity(textPass);
}
});
listfinal.setOnItemClickListener(this);
File fileWithinMyDir = getApplicationContext().getFilesDir();
loadbtn = (Button) findViewById(R.id.loadList);
loadbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
File myDir = getFilesDir();
File dir = new File(myDir + "/text/");
String[] files = dir.list();
//String[] files = getApplicationContext().fileList();
List list = new ArrayList();
for (int i =0; i < files.length; i++){
list.add(files[i]);
}
ArrayAdapter ad = new ArrayAdapter(TextMenu.this, android.R.layout.simple_list_item_1,
android.R.id.text1, list);
listfinal.setAdapter(ad);
}
});
}
在我的机器人最明显我有权限
android:minSdkVersion="5"
android:targetSdkVersion="15" />
更多推荐
所有评论(0)