I'm trying to learn how to create apps and got stuck at the very beginning. I read lots of topics about this issue and still couldn't manage to find out how to do this. I think I got the reading from text file part right but don't know how to display it. Can someone please help me? Thanks.
MainActivity.java
public class MainActivity extends AppCompatActivity { public void main(String[] args) throws Exception { FileReader file = new FileReader("C:/Users/Eothen/AndroidStudioProjects/FutbolBorsasi/app/src/main/res/infobank.txt"); BufferedReader reader = new BufferedReader(file); String line = reader.readLine(); while (line != null) { line = reader.readLine(); System.out.println("line"); } reader.close(); } activity_main.xml
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="@string/nameTextView" android:id="@+id/nameTextView" android:layout_below="@+id/ppImageView" android:layout_centerHorizontal="true" android:textSize="25sp" android:layout_marginTop="25dp" android:background="@drawable/backgroundtextview" android:gravity="center_vertical|center_horizontal" /> strings.xml
<string name="nameTextView">DISPLAY HERE</string> infobank.txt
READ HERE Edit: This Worked
public class MainActivity extends AppCompatActivity { String line; TextView view; @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); AssetManager am = getAssets(); try { InputStream is = am.open("test.txt"); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); line = reader.readLine(); view = (TextView) findViewById(R.id.nameTxt); view.setText(line); } catch (Exception e) { e.printStackTrace(); } }