H
H
Helig2018-08-06 15:49:44
Java
Helig, 2018-08-06 15:49:44

How to display the contents of a file?

Druste, I need help. I need to display the title of a txt file followed by its contents. How to record it then I understood how to view the contents of a particular file - I understood. But if I don't know the name of the file, then I can't do anything with it.
Briefly about how I write data to a file:

private EditText editlist, editlist2, editlist3, editlist4;
    private TextView showtextlist;
    public int nummin, numsec, resulttimenum;

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sactivitynew);

        editlist = (EditText)findViewById(R.id.editText);
        editlist2 = (EditText)findViewById(R.id.editText2);
        editlist3 = (EditText)findViewById(R.id.editText3);
        editlist4 = (EditText)findViewById(R.id.editText4);

        if (editlist3.getText().length() == 0)flagPointnum1 = 1;
        if (editlist4.getText().length() == 0)flagPointnum2 = 1;


        showtextlist = (TextView)findViewById(R.id.textlist);

    }

 public void writelistmethode (View view){


        String myTxt = editlist.getText().toString();
        String myTxt2 = editlist2.getText().toString();
        String myTxt3 = editlist3.getText().toString();
        String myTxt4 = editlist4.getText().toString();

        nummin = Integer.parseInt(myTxt3);
        numsec = Integer.parseInt(myTxt4);

        resulttimenum = (nummin * 60000) + (numsec * 1000);

        String resulttimestr = Integer.toString(resulttimenum);



        try {
            FileOutputStream fileOutput = openFileOutput(myTxt2 + ".txt", MODE_PRIVATE);
            fileOutput.write(myTxt.getBytes());
            fileOutput.write("\n".getBytes());
            fileOutput.write(resulttimestr.getBytes());
            fileOutput.close();
            editlist.setText("");
            editlist3.setText("");
            editlist4.setText("");
            Toast.makeText(SActivitynew.this, "Save to " + myTxt2 + ".txt ", Toast.LENGTH_LONG).show();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }




    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaxLich, 2018-08-07
@MaxLich

Use BufferedReader. Or right away Files.readAllLines(Path path).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question