package com.example.comm118.osgumifood; import android.app.Activity; import android.os.Bundle; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream;
public class readTxext extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_food); }
public readTxext() { readText(); }
private String readText() { String data = null; InputStream inputStream = getResources().openRawResource(R.raw.text1) ; //여기서안됨
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); int i; try { i = inputStream.read(); while (i != -1) { byteArrayOutputStream.write(i); i = inputStream.read(); } data = new String(byteArrayOutputStream.toByteArray(),"MS949"); inputStream.close(); } catch (IOException e) { e.printStackTrace(); } return data ; } public String readStringText() { return readText() ; } }
===============================================================
InputStream inputStream = getResources().openRawResource(R.raw.text1) ;
여기서 에러가 잡힙니다.
되는 클래스=====================================================
package com.example.comm118.osgumifood; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream;
public class FoodActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_food);
Food food = new Food();
toDay today = new toDay() ;
readTxext txt = new readTxext();//문제발생
TextView dateText = (TextView) findViewById(R.id.date) ;
TextView timeText = (TextView) findViewById(R.id.time1) ;
TextView foodText = (TextView) findViewById(R.id.food1) ; TextView timeText2 = (TextView) findViewById(R.id.time2) ; TextView foodText2 = (TextView) findViewById(R.id.food2) ; TextView timeText3 = (TextView) findViewById(R.id.time3) ; TextView foodText3 = (TextView) findViewById(R.id.food3) ; dateText.setText(food.toDateString()); timeText.setText(food.toTimeString()); foodText.setText(txt.readStringText()); timeText2.setText(food.toTimeString()); foodText2.setText(today.printDay()); timeText3.setText(food.toTimeString()); foodText3.setText(readTxt()); } private String readTxt() { String data = null; InputStream inputStream = getResources().openRawResource(R.raw.text1); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); int i; try { i = inputStream.read(); while (i != -1) { byteArrayOutputStream.write(i); i = inputStream.read(); } data = new String(byteArrayOutputStream.toByteArray(),"MS949"); inputStream.close(); } catch (IOException e) { e.printStackTrace(); } return data; } }
여기서는 됩니다.