我需要在智能手机内存中写入文本文件,然后需要通过USB电缆将此.txt文件复制到您的计算机并访问他的内存(此复制过程将使手动,需要找到该文件并了解将记录哪个存储位置)。Writer文件内存中的TXT内部android
我使用下面的代码,当我运行时显示没有错误,但我不知道这个录音是否存在,以及我不知道智能手机上的目录应该是什么。
此功能按钮来调用函数salvarInternalStorage
findViewById(R.id.distance_demo_button).setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Trilateration tri = new Trilateration(v.getContext());
try {
tri.salvarInternalStorage("Trying to Save This text Example");
} catch (IOException e) {
e.printStackTrace();
}
startListBeaconsActivity(DistanceBeaconActivity.class.getName());
}
});
这个功能,你应该写为“FILE.TXT”通过参数传递的文本。
public void salvarInternalStorage(String texto) throws IOException{
// Use Activity method to create a file in the writeable directory
FileOutputStream fos = context.openFileOutput("FileTeste.txt", context.MODE_PRIVATE);
// Create buffered writer
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos));
writer.write(String.valueOf(texto.getBytes()));
writer.close();
}
测试中的Android 6.0摩托±3 –
此代码老乡去了,上的是Android 5.1,MOTO G1的工作,但不是在Android 6.0。 –