Reading from a text file is no longer working

Katalon Studio Version:
KSE 8.6.6, Build 208
Windows 11 Enterprise (64-bit)
Chrome Version: 117.0.5938.132 (Official Build) (32-bit)

Reading from a text file is no longer working for our team, is anyone else seeing this issue?
The following previously worked (How would I read from a text file - #5 by Dave_Evers).

Import section:

import java.io.File.*

Test case body:

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

=============== ROOT CAUSE =====================


For trouble shooting, please visit: https://docs.katalon.com/katalon-studio/docs/troubleshooting.html
================================================

10-03-2023 11:33:10 AM Test Cases/01 How_to_cases/25 Katalon_tips/00 ReadFromDave.txt

Elapsed time: 0.385s

Test Cases/01 How_to_cases/25 Katalon_tips/00 ReadFromDave.txt FAILED.
Reason: java.io.FileNotFoundException: C:\Users\qatester\Downloads\TestFiles\mytest.txt (The system cannot find the file specified)
	at 00 ReadFromDave.txt.run(00 ReadFromDave.txt:4)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:448)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:144)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:135)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1696357986233.run(TempTestCase1696357986233.groovy:25)

1 Like

Sorry folks this is working as expected we had a naming typo in our text file… File name was mytest…txt when it should have been mytest.txt The error was having two periods after the file name.

import java.nio.file.Path
import java.nio.file.Paths
import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

//Hardcoded path
File file1 = new File('C:/Users/qatester/Downloads/TestFiles/mytext.txt')
println file1.getText("UTF-8")

//system user path
def SysUserDownloadDir = (System.getProperty('user.home'))
Path SysUserPath = Paths.get(SysUserDownloadDir)
Path SysUserTestFile = SysUserPath.resolve('Downloads').resolve('TestFiles').resolve('mytext.txt')
def textFile = SysUserTestFile.toString()
println("textFile: " + textFile)
//result = textFile: C:\Users\qatester\Downloads\TestFiles\mytext.txt
File file2 = new File(textFile)
String FileContents = file2.getText("UTF-8")
println FileContents

5 Likes