hi,
i am facing the problem in writing user input to file i.e,
i got some sample code of user input below i have mentioned the code
in the code user inputs some data, that data i need to wirte to file,
if i use out.write() its giving error, i am not able to type cast edittext to byte
please help
how to write to user input to file ? or
how to pass the user input to native code funtion ?
java code :
package co.readfile.ex1;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class ReadFileActivity extends Activity
{
private static String FILENAME = "ex1.txt";
private static String PATH = "/data/data/co.readfile.ex1/files/" + FILENAME;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button okButton = (Button) findViewById(R.id.ok);
okButton.setOnClickListener(okOnClickListener);
Button cancelButton = (Button) findViewById(R.id.cancel);
cancelButton.setOnClickListener(cancelOnClickListener);
TextView tv = new TextView(this);
}
private Button.OnClickListener okOnClickListener = new Button.OnClickListener()
{
public void onClick(View v)
{
EditText edit_text = (EditText)
findViewById(R.id.message_text);
CharSequence edit_text_value = edit_text.getText();
setTitle("Hello:"+edit_text_value);
ObjectOutputStream objectOut = null;
try
{
FileOutputStream out = openFileOutput(FILENAME, Context.MODE_PRIVATE);
objectOut = new ObjectOutputStream(new BufferedOutputStream(out));
out.write(edit_text_value); // error at this line ?
}
catch (IOException ex)
{
//.append("Unable to write test file from Java, see logcat for details");
}
}
};
private Button.OnClickListener cancelOnClickListener = new Button.OnClickListener()
{
public void onClick(View v)
{
finish();
}
};
}
main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Who you are?"
/>
<EditText
android:id = "@+id/message_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id = "@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK" />
<Button
android:id = "@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel" />
</LinearLayout>


