我是android开发新手。我试图在Android设备上用数字编写一个文件。我可以将文件存储在内部存储器中,但目前我无法在此文件上写入。Android内部存储文件写入无法正常工作
这是我的代码。 有任何建议透露给我。
int count=0;
FileOutputStream outputStream;
BufferedReader input=null;
File file=new File(getCacheDir(),"example.txt");
if(file.exists()==true){
try {
input = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String line;
StringBuilder builder=new StringBuilder();
while((line=input.readLine())!=null){
builder.append(line);
}
String g=builder.toString();
Toast.makeText(getApplicationContext(),"Count - " + g,Toast.LENGTH_LONG).show();
}catch (IOException e){
}
}else {
try {
count=count+1;
outputStream = new FileOutputStream(file);
outputStream.write(count);
outputStream.close();
Toast.makeText(getApplicationContext(),"File - "+file.getPath().toString(),Toast.LENGTH_LONG).show();
}catch (IOException e){
Toast.makeText(getApplicationContext(),"Error creating this file",Toast.LENGTH_LONG).show();
}
}
感谢
@ChiragSavsani谢谢。 –
现在工作吗? –
@ChiragSavsani - 仍然不起作用 –