title: Not able to read a file present in the directory in Jenkins
body: <p>I am trying to read a file in a jenkins pipeline. I create this file using Linux 'tee' command.
  I try to read the file using in built java functions such as Files.readAllLines in java.nio or BufferedReader in java.io package.
  None of the either 2 cases work.</p>
  <p>The reason I want to use either of these 2 or a similar technique is because I have to read this file in a shared library and not in Jenkins file.
  I try to read the file in a Jenkins pipeline so as to test whether these 2 methods work or not.</p>
  <p>How can I use these techniques to read already existing file in my workspace ?</p>
  <p>Also, I tried to use jenkins readFile method and it works but I think I cannot use it in my shared library.</p>
  <p>My Jenkins file is:</p>
  <pre><code>import java.io.file.*
  
  pipeline {
  agent any
  
  stages {
      stage('Scan Timeout Test') {
          steps {
              script {
                  sh '''echo &quot;Running ls before ...&quot;
  ls -lt
                  '''
                  sh 'ls -lt | tee lslog.txt'
                  sh '''pwd
                  ls -lt
                  '''
                  getLogs(&quot;$WORKSPACE/lslog.txt&quot;)
              }
          }
      } //end of stage
    }
  }
  
  def getLogs(logPath) throws IOException {
      //println &quot;Reading $logPath...&quot;
      //def text = readFile logPath
      //println text
       /*println &quot;[INFO] Reading Log File: &quot; + Paths.get(logPath).toAbsolutePath().toString()
       try {
         return Files.readAllLines(Paths.get(logPath), StandardCharsets.UTF_8);
       } catch(IOException e){
           println &quot;[ERROR] Failed to read file '&quot;+logPath+&quot;': &quot;+e.getMessage()
           throw e
       }*/
       BufferedReader bufReader = new BufferedReader(new FileReader(logPath)); 
       ArrayList&lt;String&gt; listOfLines = new ArrayList&lt;&gt;(); 
   
       String line = bufReader.readLine(); 
   
       while (line != null) { 
           listOfLines.add(line); 
           line = bufReader.readLine(); 
       }
   
       bufReader.close();
       return listOfLines
  }
  
  
  The output that I get in my Jenkins console is: 
  + pwd
  /jenkins/workspace/test
  + ls -lt
  total 44
  -rw-r--r-- 1 root root   526 Aug 21 11:32 lslog.txt
  drwxr-xr-x 2 root root   173 Aug 21 11:32 vars
  drwxr-xr-x 3 root root   109 Aug 21 11:32 resources
  drwxr-xr-x 4 root root    29 Aug 21 11:32 src
  -rw-r--r-- 1 root root 22783 Aug 21 11:32 README.md
  -rw-r--r-- 1 root root   602 Aug 21 11:32 build.gradle
  drwxr-xr-x 3 root root    21 Aug 21 11:32 gradle
  -rw-r--r-- 1 root root  5296 Aug 21 11:32 gradlew
  -rw-r--r-- 1 root root  2176 Aug 21 11:32 gradlew.bat
  drwxr-xr-x 2 root root   118 Aug 21 11:32 integration-tests
  [Pipeline] }
  [Pipeline] // script
  [Pipeline] }
  [Pipeline] // stage
  [Pipeline] }
  [Pipeline] // withEnv
  [Pipeline] }
  [Pipeline] // node
  [Pipeline] End of Pipeline
  java.io.FileNotFoundException: /jenkins/workspace/test/lslog.txt (No such file or directory)
  at java.io.FileInputStream.open0(Native Method)
  </code></pre>
  <p>Using ls -lt, I can see that my file, lslog.txt is created in the directory but I cannot read it.</p>