노련한 Java 전문가가 필요로하는 앱이 있습니다. 엔진은 완벽하게 작동하지만 데이터를 텍스트 파일에 저장할 수 없습니다. 또한, 필자의 태블릿을 밧줄로 묶고, 이전 응용 프로그램을 제거하고, apk를 복사하고, 에뮬레이터의 디스크에 쓸 수 없기 때문에 파일 작업을 디버깅 할 때마다 다시 설치해야합니다. 자바의 텍스트 파일에 쓰기
나는 추가 :<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
을 응용 프로그램 태그의 매니페스트 외부뿐만 아니라 시도 수많은 쓰기로 파일 방법에 관한 것이다. 예외는 (현재 시도에 따라) eacces이거나 파일이 존재하지 않습니다. 나는 또한 솔루션을 찾기 위해 하루 종일 인터넷 검색을했습니다. 아무나 아이디어있어?
// this is a canned method that should presumably work
private void writeStringToTextFile(String s, String f){
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath());
dir.mkdirs();
File file = new File(dir, f);
try{
FileOutputStream f1 = new FileOutputStream(file,false); //True = Append to file, false = Overwrite
PrintStream p = new PrintStream(f1);
p.print(s);
p.close();
f1.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
} }
// this is the save method
// it has been modified a little less than a million times today
// some lines may be unnecessary because I have tried several approaches
public void saveSystem(View view){
String s="";
String FILENAME = "data/data/TopExpertAndroid/" + fileName;
FileOutputStream f;
File file = new File(FILENAME);
if(!(file.exists())){
try{
file.createNewFile();}
catch(Exception e){
showSplash(e.getMessage() + e.getCause(), "OK");
return;}}
try{
getFile();
if(fileName.equals("")){}
else{
f = openFileOutput(FILENAME, Context.MODE_PRIVATE);
for(int temp=0; temp<50; temp++){
for(int loop=0; loop<50; loop++){
s += topExpert.nodeBank[temp][loop].activationResponse + "\n";
s += topExpert.nodeBank[temp][loop].display + "\n";
s += topExpert.nodeBank[temp][loop].falseLink + "\n";
s += topExpert.nodeBank[temp][loop].identifier + "\n";
if(topExpert.nodeBank[temp][loop].isTop){
s += "true";}
else{
s += "false";}
s += "\n" + topExpert.nodeBank[temp][loop].trueLink + "\n";}}
writeStringToTextFile(s,FILENAME);
}}
catch(Exception e){
showSplash(e.getMessage() + e.getCause(), "OK");}}
내가 그 빈'캐치'블록을 얼마나 좋아하는지. e.printStackTrace() (둘 다!)로 채우고 질문에 StackTrace를 추가하십시오. –