Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

how to read text file as variable in java

public static void readAsString() {
			 String lCurentDir = System.getProperty("user.dir")+"/aa.txt";
			 FileReader fr;
			try {
				fr = new FileReader(lCurentDir);
				 BufferedReader br = new BufferedReader(fr);
		            String s="";
		            s=br.readLine();
		            System.out.println(s);
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	           

		}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #read #text #file #variable #java
ADD COMMENT
Topic
Name
5+7 =