android虚拟机问题,求大神帮助,急急急急急 我想往android模拟器的"/data/"目录下新建一个.txt文件,可是程序运行后创建不成也不报错,找不到files文件夹,不知怎么回事,急急急急 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你贴一下代码 那个目录创建 有特定的方法 貌似是 java的文件创建不行 好像和 context 有关系什么的 记不清楚了 在 传智播客的 有一期的 视频中 有介绍 你可以去看看举个例子 你给你的应用保存 sharedpreferences 的时候 会在 那个 文件目录下创建新的文件 package com.tao.file;import java.io.IOException;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;public class FilePhone extends Activity { /** Called when the activity is first created. */ private EditText filename,filecontent; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); filename =(EditText) this.findViewById(R.id.filename); filecontent =(EditText)this.findViewById(R.id.filecontent); Button button=(Button)this.findViewById(R.id.button); button.setOnClickListener(new FileSaveListener()); } private final class FileSaveListener implements View.OnClickListener{ public void onClick(View v) { String name =filename.getText().toString(); String content =filecontent.getText().toString(); FileService service = new FileService(new FilePhone()); try { service.save(name,content); Toast.makeText(new FilePhone(),R.string.success, Toast.LENGTH_LONG).show(); } catch (IOException e) { Toast.makeText(new FilePhone(), R.string.fail, 1).show(); } } }}/** * */package com.tao.file;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import android.content.Context;import android.widget.Toast;/** * @author Administrator * */public class FileService { private Context context; public FileService(Context context) { this.context = context; } public void save( String filename,String fileconten) throws IOException { FileOutputStream outputstream = context.openFileOutput(filename,Context.MODE_PRIVATE ); outputstream.write(fileconten.getBytes()); outputstream.close(); }}<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tao.file" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/al" android:label="@string/app_name"> <activity android:name=".FilePhone" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /></manifest> 你想往filename里面写入fileconten这个内容是吗? 虚拟机启动完成后,show view→FileExplorer→data/data/files,在data文件夹应该看到files文件夹,为什么我的看不到,知道是权限问题,但我不知道怎么设置,如下图 我觉得你是代码有问题啊往rom里写入不需要权限吧,往SD卡里写入才要权限。 你创建的这个文件应该是在/data/data/你的包名/files目录下吧,兄台去这个目录找下看看 /data/data/com.tao.file/files目录下看看有不? 新手求助,如何获得GridView中的各个元素 如何获得启动后的service的实例 帮忙改个错误,谢谢 请教大家个问题 新手求解 android使用google ADK开发无法识别设备的问题 拿到一个APK,怎么准确地判断它是debug签名还是release签名? android 图表控件问题 android页卡添加横向滚动条 android定制的设备7.1.1系统,怎么处理运行时权限 android4.0, 应用程序显示方式(launcher上显示)调整问题 使用Media出错啊!
那个目录创建 有特定的方法 貌似是 java的文件创建不行 好像和 context 有关系什么的 记不清楚了
在 传智播客的 有一期的 视频中 有介绍 你可以去看看
举个例子 你给你的应用保存 sharedpreferences 的时候 会在 那个 文件目录下创建新的文件
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;public class FilePhone extends Activity {
/** Called when the activity is first created. */
private EditText filename,filecontent;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
filename =(EditText) this.findViewById(R.id.filename);
filecontent =(EditText)this.findViewById(R.id.filecontent);
Button button=(Button)this.findViewById(R.id.button);
button.setOnClickListener(new FileSaveListener());
}
private final class FileSaveListener implements View.OnClickListener{ public void onClick(View v) {
String name =filename.getText().toString();
String content =filecontent.getText().toString();
FileService service = new FileService(new FilePhone());
try {
service.save(name,content);
Toast.makeText(new FilePhone(),R.string.success, Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(new FilePhone(), R.string.fail, 1).show(); }
}
}
}
/**
*
*/
package com.tao.file;import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;import android.content.Context;
import android.widget.Toast;/**
* @author Administrator
*
*/
public class FileService {
private Context context;
public FileService(Context context) {
this.context = context;
}
public void save( String filename,String fileconten) throws IOException {
FileOutputStream outputstream = context.openFileOutput(filename,Context.MODE_PRIVATE );
outputstream.write(fileconten.getBytes());
outputstream.close();
}}<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tao.file"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/al" android:label="@string/app_name">
<activity android:name=".FilePhone"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> </application>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
往rom里写入不需要权限吧,往SD卡里写入才要权限。