How would I read from a text file

My setup:
Windows 7, 64 bit
Katalon Studio, Version: 6.1.5, Build: 3

When i run the following I get an error as listed below:

import com.sun.jna.platform.FileUtils

File file = new File("C:\\Users\\devers\\Downloads\\TestFiles\\dave.txt")
String text = FileUtils.readFileToString(file)
println text


06-11-2019 10:55:47 AM Test Cases/0 HOW_TO_CASES/27 How-to read from file
Elapsed time: 0.233s
Test Cases/0 HOW_TO_CASES/27 How-to read from file FAILED.
groovy.lang.MissingMethodException: No signature of method: static com.sun.jna.platform.FileUtils.readFileToString() is applicable for argument types: ( values: [C:\Users\devers\Downloads\TestFiles\dave.txt]
	at 27 How-to read from How-to read from file:4)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(
	at com.kms.katalon.core.main.TestCaseExecutor.execute(
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$ Source)


File file = new File("C:\\Users\\devers\\Downloads\\TestFiles\\dave.txt")
println file.getText("UTF-8")

This uses the native

my advice:
kindly ugrdade to an up to date microsoft OS or migrate to *nix


this is one way to read .txt file

import com.kms.katalon.core.util.KeywordUtil

String path = System.getProperty("user.dir")+"\\demoData.txt";

List l = CustomKeywords.''(path)

String s = l.get(1);
KeywordUtil log = new KeywordUtil()
log.logInfo("DEBUG value is "+s)

  Iterator<String> itr = l.iterator();
  while (itr.hasNext()){

import java.nio.charset.StandardCharsets;
import java.nio.file.*;

public class read {

	public List<String> readFileInList(String fileName) {
		List<String> lines = Collections.emptyList();
		try {
			lines = Files.readAllLines(Paths.get(fileName), StandardCharsets.UTF_8);
		catch (IOException e) {
		return lines;

Thanks guys!

I used Russ’ suggestion which works perfectly.

File file = new File("C:\\Users\\devers\\Downloads\\TestFiles\\dave.txt")
String FileContents = file.getText("UTF-8")
println FileContents
1 Like

Come on Ibus, please play nice.

Win7 is a supported OS by both Microsoft and Katalon right now. Kalaton may even support it beyond its MS support life.

I use Win7 and will continue to do so until I’m literally forced, kicking and screaming, to use Win10+.

I do play nice.
I know how addictive is w7 but unfortunately M$ has different opinions. you will see … this year may be the last for his life.
i did use it too, for long time, since the early begining.
lucky me, at home i migrated everything i own to linux and at work i have w10 provided by the company

Currently, end of life is Jan 2020.

april 2020 if i remember it right. so, it’ less than a year … you still have time to find alternate options
ok, is not this year but still less than one year

hello, does anyone has an idea how to read a value from the txt file? for example i have a one time passcode that is displayed into a sms.txt, any idea how to get this generated one time passcode an insert it into katalon to write it into the text box?

Please follow below tutorial