title: Read a file from the another location using JSch
body: <p>Here is my code to read a file from the another location using JSch</p>
  
  <pre><code>import com.jcraft.jsch.*;
  import java.io.BufferedReader;
  import java.io.*;
  import java.util.Vector;
  
  public class SftpClient {
      public static void main(String args[]) {
          JSch jsch = new JSch();
          Session session = null;
          FileReader reader =null;
          BufferedReader buffer = null;
          try 
          {
  .
              session = jsch.getSession("userName", "Ip Address");
              java.util.Properties config = new java.util.Properties(); 
              config.put("StrictHostKeyChecking", "no");
              session.setConfig(config);  
              session.setPassword("password");                
              session.connect();              
              Channel channel = session.openChannel("sftp");
              channel.connect();
              ChannelSftp sftpChannel = (ChannelSftp) channel;
              System.out.println("Is connected to IP:"+channel.isConnected());
              Vector ls=sftpChannel.ls("/misc/downloads/");
              for(int i=0;i&lt;ls.size();i++){
                 System.out.println("Ls:"+ls.get(i));
              }
              sftpChannel.cd("/misc/downloads/");             
              File file = new File("Text.txt");
              sftpChannel.put(new FileInputStream(file),"Text.txt");              
              reader = new FileReader(file);
              buffer = new BufferedReader(reader);                
              String getLine = "";
              while ((getLine = buffer.readLine())!=null)
              {
                 System.out.println("Line: "+getLine);
              }
              sftpChannel.exit();             
              session.disconnect();
          }
          catch (JSchException e) {
              e.printStackTrace();
          }
          catch (Exception e){
              e.printStackTrace();
          } 
          finally{
              try{
                 if(reader!=null)
                    reader.close();
                 if(buffer!=null)
                    buffer.close();
              }
              catch(Exception e){
                 System.out.println("Exception:"+e);
              }
          }
      }
  </code></pre>
  
  <p>}</p>
  
  <p>Output of the code is :</p>
  
  <pre><code>Is connected to IP:true
  Ls:-rw-r--r--    1 root     root          733 Jul 19 17:46 Text.txt
  java.io.FileNotFoundException: Text.txt (The system cannot find the file specified)
      at java.io.FileInputStream.open(Native Method)
      at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:103)
      at SftpClient.main(SftpClient.java:34)
  </code></pre>
  
  <p>I am getting the FileNotFoundException, but before that I made SOP to list all the files in the /misc/downloads/ path using ls. </p>
  
  <p>What can I do to solve this problem?</p>