public class AndroidInternetTxt extends Activity { TextView textMsg; TextView textPrompt; //private ContextWrapper context; //private String fileName; //String filePath = context.getFilesDir().getAbsolutePath();//returns current directory. //File file = new File(filePath, fileName); final String textSource = "D:/text.txt"; //http://sites.google.com/site/androidersite/text.txt /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textPrompt = (TextView) findViewById(R.id.textprompt); textMsg = (TextView) findViewById(R.id.textmsg); textPrompt.setText("Wait..."); URL textUrl; try { textUrl = new URL(textSource); BufferedReader bufferReader = new BufferedReader( new InputStreamReader(textUrl.openStream())); String StringBuffer; String stringText = ""; while ((StringBuffer = bufferReader.readLine()) != null) { stringText += StringBuffer; } bufferReader.close(); textMsg.setText(stringText); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); textMsg.setText(e.toString()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); textMsg.setText(e.toString()); } textPrompt.setText("Finished!"); } }
final String textSource = "file:///D:/text.txt";
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)