I have prepared a Java Class with name SshAgent. In this same class we are passing arguments hostname,username and password and connecting via SSH. The issue is getting while executing command to the server.

Re: How to connect and fire command to SSH server using Gyanmed SSH2 API.

Please wrap code in [code=Java] [/code] tags to preserve formatting.

Just looking at the error and scanning briefly over the code, an OutOfMemoryError suggests that you are trying to load way too much into memory, or at minimum preparing too load to much. Why do you ensure capacity every loop? It may or may not do anything, and isn't likely to help, removing that may solve that problem altogether.

Also try to create a SSCCE (Simple Self-Contained Complete Example) that demonstrates just reading the file if the problem persists.