How to save Strings from a file read?

Asked

Viewed 65 times

2

Guys I’m reading a.txt file and would like to save all the strings as I could save it all ? Below follows my writing code I am using , in case I would like to guard the String line .

public static void main(String[] args) throws IOException {
              try {
                  File f = new File ("c:/teste.txt");
                  InputStream is = new FileInputStream("c:/teste.txt");
                    InputStreamReader isr = new InputStreamReader(is);
                    BufferedReader reader = new BufferedReader(isr);
                    String linha = reader.readLine();


                    while (linha != null) {



                        System.out.println(linha);

                        linha = reader.readLine();

                        }
                        reader.close();

            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

1 answer

3


Browser other questions tagged

You are not signed in. Login or sign up in order to post.