Firstly I'm crap at english, I hope you'll understand everything. I'm trying to create an app that create a simple file "lol.txt" which contains "hello world!". i'm a bit noob, I tried to follow tutos on internet.
The thing is, I succeed to reach the debug line "file created?" but I can't find the folder of my app nor the .txt file that I created.
Is my code wrong? I can't find any folder of my app when I upload it on my phone with eclipse.
MainActivity.java
package com.example.brosselesdents;
import java.io.File;
import java.io.FileOutputStream;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener{
int compteur = 0;
TextView text1;
String fileName = "lol.txt";
FileOutputStream outputStream;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text1 = (TextView)findViewById(R.id.textView1);
Button button1;
button1 = (Button)findViewById(R.id.button1);
final String string = "Hello world!";
button1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
try {
outputStream = openFileOutput(fileName, Context.MODE_PRIVATE);
outputStream.write(string.getBytes());
outputStream.close();
text1.setText("File created?");
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.brosselesdentsbatards.MainActivity"
android:id="@+id/layout1">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="91dp"
android:text="Button" />
</RelativeLayout>
If you have any idea, like the default folder (I searched on "android/data/com.example.(...)/" ) or maybe a mistake in my code?
Thank you very much. I apreaciate your help.