java print in textarea text file in reverse order
up vote
0
down vote
favorite
I'm using this code, it runs well but i need to add "n
" to each line
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
filename = "Reverse.txt";
file = new File(filename);
try (final Stream<String> lines = Files.lines(Paths.get(filename)))
lines.collect(Collectors.toCollection(LinkedList::new))
.descendingIterator()
.forEachRemaining(jTextArea1::append); // <<<<<<< need "n"
catch (IOException ex)
Logger.getLogger(TextAreaReverseReadFrame.class.getName()).log(Level.SEVERE, null, ex);
java
New contributor
add a comment |
up vote
0
down vote
favorite
I'm using this code, it runs well but i need to add "n
" to each line
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
filename = "Reverse.txt";
file = new File(filename);
try (final Stream<String> lines = Files.lines(Paths.get(filename)))
lines.collect(Collectors.toCollection(LinkedList::new))
.descendingIterator()
.forEachRemaining(jTextArea1::append); // <<<<<<< need "n"
catch (IOException ex)
Logger.getLogger(TextAreaReverseReadFrame.class.getName()).log(Level.SEVERE, null, ex);
java
New contributor
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm using this code, it runs well but i need to add "n
" to each line
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
filename = "Reverse.txt";
file = new File(filename);
try (final Stream<String> lines = Files.lines(Paths.get(filename)))
lines.collect(Collectors.toCollection(LinkedList::new))
.descendingIterator()
.forEachRemaining(jTextArea1::append); // <<<<<<< need "n"
catch (IOException ex)
Logger.getLogger(TextAreaReverseReadFrame.class.getName()).log(Level.SEVERE, null, ex);
java
New contributor
I'm using this code, it runs well but i need to add "n
" to each line
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
filename = "Reverse.txt";
file = new File(filename);
try (final Stream<String> lines = Files.lines(Paths.get(filename)))
lines.collect(Collectors.toCollection(LinkedList::new))
.descendingIterator()
.forEachRemaining(jTextArea1::append); // <<<<<<< need "n"
catch (IOException ex)
Logger.getLogger(TextAreaReverseReadFrame.class.getName()).log(Level.SEVERE, null, ex);
java
java
New contributor
New contributor
edited 22 hours ago
SaviNuclear
692517
692517
New contributor
asked 23 hours ago
patel
62
62
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
Simply try to change
.forEachRemaining(jTextArea1::append);
to:
.forEachRemaining(singleLine -> jTextArea1.append(singleLine + "n"));
I think it would be more stream-esque if you add n to the text with a separate .map call
– Tim Castelijns
23 hours ago
Might be, thanks, but well, my wild guess is that IDE helped the OP a bit too much, it's good to know that you can change method references to expressions like this :)
– Pijotrek
23 hours ago
I don't understand what that has to do with my comment
– Tim Castelijns
23 hours ago
thanks Pijotrek, your code solved my problem, why I can not vote up ?
– patel
20 hours ago
@patel consider accepting this answer then
– Pijotrek
20 hours ago
add a comment |
up vote
0
down vote
You can transform each line at source, meaning adding a map instruction just before the collect one:
lines.map(element -> element + 'n').collect(Collectors.toCollection(LinkedList::new)).descendingIterator()
.forEachRemaining(testBuilder::append);
thanks Bsquare, at the beginning I did not understand your solution, but it works well
– patel
15 hours ago
Nice it solves your issue. On Stackoverflow you could give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.
– Bsquare
14 hours ago
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Simply try to change
.forEachRemaining(jTextArea1::append);
to:
.forEachRemaining(singleLine -> jTextArea1.append(singleLine + "n"));
I think it would be more stream-esque if you add n to the text with a separate .map call
– Tim Castelijns
23 hours ago
Might be, thanks, but well, my wild guess is that IDE helped the OP a bit too much, it's good to know that you can change method references to expressions like this :)
– Pijotrek
23 hours ago
I don't understand what that has to do with my comment
– Tim Castelijns
23 hours ago
thanks Pijotrek, your code solved my problem, why I can not vote up ?
– patel
20 hours ago
@patel consider accepting this answer then
– Pijotrek
20 hours ago
add a comment |
up vote
0
down vote
accepted
Simply try to change
.forEachRemaining(jTextArea1::append);
to:
.forEachRemaining(singleLine -> jTextArea1.append(singleLine + "n"));
I think it would be more stream-esque if you add n to the text with a separate .map call
– Tim Castelijns
23 hours ago
Might be, thanks, but well, my wild guess is that IDE helped the OP a bit too much, it's good to know that you can change method references to expressions like this :)
– Pijotrek
23 hours ago
I don't understand what that has to do with my comment
– Tim Castelijns
23 hours ago
thanks Pijotrek, your code solved my problem, why I can not vote up ?
– patel
20 hours ago
@patel consider accepting this answer then
– Pijotrek
20 hours ago
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Simply try to change
.forEachRemaining(jTextArea1::append);
to:
.forEachRemaining(singleLine -> jTextArea1.append(singleLine + "n"));
Simply try to change
.forEachRemaining(jTextArea1::append);
to:
.forEachRemaining(singleLine -> jTextArea1.append(singleLine + "n"));
answered 23 hours ago
Pijotrek
4821416
4821416
I think it would be more stream-esque if you add n to the text with a separate .map call
– Tim Castelijns
23 hours ago
Might be, thanks, but well, my wild guess is that IDE helped the OP a bit too much, it's good to know that you can change method references to expressions like this :)
– Pijotrek
23 hours ago
I don't understand what that has to do with my comment
– Tim Castelijns
23 hours ago
thanks Pijotrek, your code solved my problem, why I can not vote up ?
– patel
20 hours ago
@patel consider accepting this answer then
– Pijotrek
20 hours ago
add a comment |
I think it would be more stream-esque if you add n to the text with a separate .map call
– Tim Castelijns
23 hours ago
Might be, thanks, but well, my wild guess is that IDE helped the OP a bit too much, it's good to know that you can change method references to expressions like this :)
– Pijotrek
23 hours ago
I don't understand what that has to do with my comment
– Tim Castelijns
23 hours ago
thanks Pijotrek, your code solved my problem, why I can not vote up ?
– patel
20 hours ago
@patel consider accepting this answer then
– Pijotrek
20 hours ago
I think it would be more stream-esque if you add n to the text with a separate .map call
– Tim Castelijns
23 hours ago
I think it would be more stream-esque if you add n to the text with a separate .map call
– Tim Castelijns
23 hours ago
Might be, thanks, but well, my wild guess is that IDE helped the OP a bit too much, it's good to know that you can change method references to expressions like this :)
– Pijotrek
23 hours ago
Might be, thanks, but well, my wild guess is that IDE helped the OP a bit too much, it's good to know that you can change method references to expressions like this :)
– Pijotrek
23 hours ago
I don't understand what that has to do with my comment
– Tim Castelijns
23 hours ago
I don't understand what that has to do with my comment
– Tim Castelijns
23 hours ago
thanks Pijotrek, your code solved my problem, why I can not vote up ?
– patel
20 hours ago
thanks Pijotrek, your code solved my problem, why I can not vote up ?
– patel
20 hours ago
@patel consider accepting this answer then
– Pijotrek
20 hours ago
@patel consider accepting this answer then
– Pijotrek
20 hours ago
add a comment |
up vote
0
down vote
You can transform each line at source, meaning adding a map instruction just before the collect one:
lines.map(element -> element + 'n').collect(Collectors.toCollection(LinkedList::new)).descendingIterator()
.forEachRemaining(testBuilder::append);
thanks Bsquare, at the beginning I did not understand your solution, but it works well
– patel
15 hours ago
Nice it solves your issue. On Stackoverflow you could give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.
– Bsquare
14 hours ago
add a comment |
up vote
0
down vote
You can transform each line at source, meaning adding a map instruction just before the collect one:
lines.map(element -> element + 'n').collect(Collectors.toCollection(LinkedList::new)).descendingIterator()
.forEachRemaining(testBuilder::append);
thanks Bsquare, at the beginning I did not understand your solution, but it works well
– patel
15 hours ago
Nice it solves your issue. On Stackoverflow you could give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.
– Bsquare
14 hours ago
add a comment |
up vote
0
down vote
up vote
0
down vote
You can transform each line at source, meaning adding a map instruction just before the collect one:
lines.map(element -> element + 'n').collect(Collectors.toCollection(LinkedList::new)).descendingIterator()
.forEachRemaining(testBuilder::append);
You can transform each line at source, meaning adding a map instruction just before the collect one:
lines.map(element -> element + 'n').collect(Collectors.toCollection(LinkedList::new)).descendingIterator()
.forEachRemaining(testBuilder::append);
answered 23 hours ago
Bsquare
1,430124
1,430124
thanks Bsquare, at the beginning I did not understand your solution, but it works well
– patel
15 hours ago
Nice it solves your issue. On Stackoverflow you could give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.
– Bsquare
14 hours ago
add a comment |
thanks Bsquare, at the beginning I did not understand your solution, but it works well
– patel
15 hours ago
Nice it solves your issue. On Stackoverflow you could give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.
– Bsquare
14 hours ago
thanks Bsquare, at the beginning I did not understand your solution, but it works well
– patel
15 hours ago
thanks Bsquare, at the beginning I did not understand your solution, but it works well
– patel
15 hours ago
Nice it solves your issue. On Stackoverflow you could give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.
– Bsquare
14 hours ago
Nice it solves your issue. On Stackoverflow you could give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.
– Bsquare
14 hours ago
add a comment |
patel is a new contributor. Be nice, and check out our Code of Conduct.
patel is a new contributor. Be nice, and check out our Code of Conduct.
patel is a new contributor. Be nice, and check out our Code of Conduct.
patel is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222214%2fjava-print-in-textarea-text-file-in-reverse-order%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password