손을주세요.안드로이드 내부 저장 장치에 파일을 쓸 수 없습니다
Android 내부 저장소의 파일 텍스트에 내용을 쓰려고합니다.
다음과 같은 스트림 메소드를 사용하고 있습니다. 그건 그렇고, 쓰지 않습니다.
해결해 주시겠습니까? 당신이 scrivi()
방법 내부 data
를 사용하지 않는 때문에
public class MainActivity extends ActionBarActivity {
File f=new File("box");
public void scrivi(String data)
{try {
FileOutputStream fos = new FileOutputStream(f);
PrintWriter pw = new PrintWriter(fos);
pw.write("");
}
catch(FileNotFoundException e){
Toast t = Toast.makeText(this, ("Il FILE NON ESITE"), Toast.LENGTH_LONG);
t.show();
}
}
public void read(String word)
{try{
FileInputStream fis = new FileInputStream(f);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String line="";
while((line=br.readLine())!=null);
println(line);
}
catch(FileNotFoundException n){Toast x = Toast.makeText(this, ("Il FILE NON SI PUO' LEGGERE"), Toast.LENGTH_LONG);
x.show();}
catch(IOException w){{Toast q = Toast.makeText(this, ("c'e' un problema"), Toast.LENGTH_LONG);
q.show();}}
}
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList lista = new ArrayList();
Intent j = getIntent();
String nome = j.getStringExtra("nome");
lista.add(nome);
scrivi(nome);
if(nome!=null)
{
Toast toast = Toast.makeText(this, ("ciao " + " " + nome), Toast.LENGTH_LONG);
toast.show();
}}
public void go(View v){
Intent intent=new Intent(this,SecondActivity.class);
startActivity(intent);
}
public void time(View c){
Intent i=new Intent(this,ActivityPicker.class);
startActivity(i);
}
public void pass(View p){
EditText nome6=(EditText)findViewById(R.id.nome6);
String inviaDati = nome6.getText().toString();
read(inviaDati);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
으악. 좋은 캐치. 질문을 잘못 읽습니다. 감사합니다 – Willis