Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Read from file properly in TextInfo activity

  • Loading branch information...
commit 59d734bfab48c9389a28c33966a6b085c16afe84 1 parent 67fa0e6
@clhodapp clhodapp authored
Showing with 16 additions and 8 deletions.
  1. +16 −8 src/edu/ua/cs/campustour/TextInfo.java
View
24 src/edu/ua/cs/campustour/TextInfo.java
@@ -1,7 +1,9 @@
package edu.ua.cs.campustour;
+import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import android.app.Activity;
import android.graphics.BitmapFactory;
@@ -31,19 +33,12 @@ public void onCreate(Bundle savedInstanceState) {
ScrollView sv = (ScrollView)findViewById(R.id.infoview);
TextView title = (TextView)findViewById(R.id.title);
TextView info = (TextView)findViewById(R.id.info);
-
title.setText(titleText);
try {
InputStream is = getAssets().open(rootdir+"info");
- int size = is.available();
-
- byte[] buffer = new byte[size];
- is.read(buffer);
- is.close();
-
- String text = new String(buffer);
+ String text = readStream(is);
info.setText(text);
if(bg == null) {
@@ -59,5 +54,18 @@ public void onCreate(Bundle savedInstanceState) {
sv.setPadding(0, h/8, 0, 0);
}
+ String readStream(InputStream is) throws IOException {
+ StringBuffer stringBuf = new StringBuffer(1024);
+ BufferedReader br = new BufferedReader(new InputStreamReader(is));
+ char[] buf = new char[1024];
+ int numRead = 0;
+ while ((numRead = br.read(buf)) != -1) {
+ String readData = String.valueOf(buf, 0, numRead);
+ stringBuf.append(readData);
+ buf = new char[1024];
+ }
+ return stringBuf.toString();
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.