Skip to content

Commit 48395d7

Browse files
committed
https://jira.baeldung.com/browse/BAEL-8627
1 parent 7c48f20 commit 48395d7

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

libraries-files/src/main/java/com/baeldung/readfileremotely/RemoteServerJsch.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.io.InputStream;
1414
import java.io.InputStreamReader;
1515

16-
1716
public class RemoteServerJsch {
1817

1918
private static final Logger LOGGER = LoggerFactory.getLogger(RemoteServerJsch.class);
@@ -22,7 +21,6 @@ public class RemoteServerJsch {
2221
private static final String PRIVATE_KEY = "PATH TO PRIVATE KEY";
2322
private static final int PORT = 22;
2423

25-
2624
public static JSch setUpJsch() throws JSchException {
2725
JSch jsch = new JSch();
2826
jsch.addIdentity(PRIVATE_KEY);
@@ -43,14 +41,14 @@ public static ChannelSftp createSftpChannel(Session session) throws JSchExceptio
4341
}
4442

4543
public static void readFileLineByLine(ChannelSftp channelSftp, String filePath) throws SftpException, IOException {
46-
InputStream stream = channelSftp.get(filePath);
47-
try (BufferedReader br = new BufferedReader(new InputStreamReader(stream))) {
48-
String line;
49-
while ((line = br.readLine()) != null) {
50-
LOGGER.info(line);
44+
InputStream stream = channelSftp.get(filePath);
45+
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream))) {
46+
String line;
47+
while ((line = bufferedReader.readLine()) != null) {
48+
LOGGER.info(line);
49+
}
5150
}
5251
}
53-
}
5452

5553
public static void disconnect(ChannelSftp channelSftp, Session session) {
5654
channelSftp.disconnect();

libraries-files/src/test/java/com/baeldung/readfileremotely/RemoteServerJschLiveTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ public void givenJsch_whenListFiles_thenSuccess() throws JSchException, SftpExce
2323
readFileLineByLine(channelSftp, REMOTE_DIR + "/examplefile.txt");
2424
disconnect(channelSftp, session);
2525
}
26-
2726
}

0 commit comments

Comments
 (0)