我想在Android的内部目录中创建一个文件,但我无法创建它,尽管创建文件和目录的标准过程。 当我在手机中安装我的应用程序时,我无法找到“com.package ...”文件夹,通过直接连接android studio安装完成。
import android.os.Environment;
import android.util.Log;
import android.widget.TextView;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class CreateLogObject {
public static final String TAG = "CreateLogObject ";
private String logId;
private TextView GPScurrentSpeed;
private TextView latitude;
private TextView longitude;
private TextView accur;
private TextView fomulaSpd;
private String Xval;
private String Yval;
private String Zval;
public CreateLogObject(String logId, TextView latitude, TextView longitude, TextView accur, TextView GPScurrentSpeed, TextView forSpeed, String X, String Y, String Z) {
this.logId = logId;
this.GPScurrentSpeed = GPScurrentSpeed;
this.latitude = latitude;
this.longitude = longitude;
this.accur = accur;
this.fomulaSpd = forSpeed;
this.Xval = X;
this.Yval = Y;
this.Zval = Z;
logDetails();
}
@Override
public String toString() {
return ", " + logId + ", " + latitude.getText() + ", " + longitude.getText() + "," + accur.getText() + ", getSpeed() Velocity:"
+ GPScurrentSpeed.getText() + ", Formula Speed:" + fomulaSpd.getText() + " , X: " + Xval + " , Y: " + Yval + " , Z: " + Zval;
}
private void logDetails() {
generateNoteOnSD("speedLog.txt", toString());
}
public void generateNoteOnSD(String sFileName, String sBody) {
try {
File root = new File(Environment.getExternalStorageDirectory(), "LogFolder");
if (!root.exists()) {
Log.d(TAG, "MISSING DIRECTORY CREATED");
root.mkdirs();
}
File gpxfile = new File(root, sFileName);
FileWriter writer = new FileWriter(gpxfile, true);
writer.append(new StringBuffer(sBody).append("\n"));
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
是的,我已经将WRITE和READ的权限授予内部/外部目录。需要立即帮助,请指导您的建议。