Java FileReader: How to assign every line in the text file to a variable -


i want every line in textdoc assigned variable.

import java.io.*; import static java.lang.system.*;  class readfile {     public static void main(string[] args) {         try {             filereader fr = new filereader("filename");             bufferedreader br = new buffered(fr);             string str;             while ((str = br.readline()) != null) {}             br.close();         } catch (ioexception e) {             out.println("file not found");         }     } } 

i suggest create list , store every line in list below:

 string str;  list<string> filetext = ....;  while ((str = br.readline()) != null) {      filetext.add(str);  }  

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -