Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess text file and read integers inside to Array ? Help Please
    primarykey
    data
    text
    <p>Having trouble with an app </p> <p>I need to read the data from a text file it contains one integer on each line and i need to read it into an array and double them then output it to another text file. however, i cant get the file to open and be read so i can add them to the array. </p> <pre><code>package com.example.doubleandsave; import java.io.File; import java.util.Scanner; import android.os.Bundle; import android.app.Activity; import android.content.res.AssetManager; import android.view.Menu; public class MainActivity extends Activity { int[] inArray; File infile = new File("inputtextfile.txt"); Scanner fsc = new Scanner(infile); AssetManager assetManager = getAssets(); Scanner fsc1 = new Scanner(assetManager.open("inputtextfile.txt")); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } } </code></pre> <p>these two lines gives me the error Default constructor cannot handle exception type IOException thrown by implicit super constructor. Must define an explicit constructor</p> <p>Anyone know how I would fix this ? #fixed# </p> <p>this is the gist of what i have to do </p> <ol> <li>Open the input (text) file with the given name (first EditText field above). This file should appear in the “assets” directory of your app. It should contain a list of grades (one per line). Read the grades into an array. (If the file does not exist, display an appropriate message in the text area of the screen labeled “Status.” above.)</li> <li>Using a method double all the values in the array. (Include this method in your main activity class and call it from the method responding to the button press.)</li> <li>Output the list of the doubled grades (one per line) to a new file with the given name (second EditText field above). This file should appear in your app’s external files directory, which can be obtained using the built-in SDK “getExternalFilesDir” method. NOTE: Check to see if the output file already exists before opening it. If it does, do not overwrite it. Display an appropriate message for the user in the status text area and don’t write anything to the file.</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload