Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Thursday 18 October 2012

Create an application to read file from the sdcard and display that file content to the screen.

Pro19Activity.java
package ps.pro19;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class Pro19Activity extends Activity {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 TextView tvcontent;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
        tvcontent=(TextView) findViewById(R.id.textView2);
        
        try
        {
         File myFile=new File("/sdcard/hello.txt");
         InputStream in=null;
         in=new FileInputStream(myFile);
         
         String msg="";
         while(in.available()>0)
         {
          msg=msg+(char)in.read();
         }
         in.close();
         tvcontent.setText(msg);

        }
        catch(Exception e)
        {
         Toast.makeText(this, e.toString(),Toast.LENGTH_LONG).show();
        }
    }
}

No comments:

Post a Comment