Sometimes we came across requirements where we
need to read the test data from notepad file and use this test data in
automation test instead of a conventional way of storing either in excel or in
the properties file.
In this article, we will learn how to read
data from Notepad or .txt file.
For this purpose, we can make use of java
built-in class File to create a new file, FileWriter, and BufferedWriter class
to write In to file, FileReader and BufferedReader Class to read this text
file.
In this example, I will read the data from the
notepad file kept on my desktop which contains google home page URL and enters
that URL in my chrome browser.
Below is the code snapshot
Hi Ankur, i am getting below error while executing same program in my local.
ReplyI have changed the path of .txt file as per my local drive.
Error:
Exception in thread "main" java.io.FileNotFoundException: C:\Users\satyendra.rajpoot\testdata.txt (The system cannot find the file specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.(Unknown Source)
at java.io.FileInputStream.(Unknown Source)
at java.io.FileReader.(Unknown Source)
at ExcelData.NotePadDataReadWrite.main(NotePadDataReadWrite.java:16)
Can you please help, same error i am also getting when i am using excel driven approach. Let me know if you any solution for this.
Thanks its very use-full.
Reply