java print in textarea text file in reverse order
up vote
-2
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
add a comment |
up vote
-2
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
add a comment |
up vote
-2
down vote
favorite
up vote
-2
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
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
edited Nov 9 at 9:40
SaviNuclear
692517
692517
asked Nov 9 at 8:31
patel
114
114
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
Nov 9 at 8:41
I don't understand what that has to do with my comment
– Tim Castelijns
Nov 9 at 8:48
thanks Pijotrek, your code solved my problem, why I can not vote up ?
– patel
Nov 9 at 12:11
add a comment |
up vote
1
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
Nov 9 at 16:34
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
Nov 9 at 17:26
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
Nov 9 at 8:41
I don't understand what that has to do with my comment
– Tim Castelijns
Nov 9 at 8:48
thanks Pijotrek, your code solved my problem, why I can not vote up ?
– patel
Nov 9 at 12:11
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
Nov 9 at 8:41
I don't understand what that has to do with my comment
– Tim Castelijns
Nov 9 at 8:48
thanks Pijotrek, your code solved my problem, why I can not vote up ?
– patel
Nov 9 at 12:11
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 Nov 9 at 8:39
Pijotrek
4841416
4841416
I think it would be more stream-esque if you add n to the text with a separate .map call
– Tim Castelijns
Nov 9 at 8:41
I don't understand what that has to do with my comment
– Tim Castelijns
Nov 9 at 8:48
thanks Pijotrek, your code solved my problem, why I can not vote up ?
– patel
Nov 9 at 12:11
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
Nov 9 at 8:41
I don't understand what that has to do with my comment
– Tim Castelijns
Nov 9 at 8:48
thanks Pijotrek, your code solved my problem, why I can not vote up ?
– patel
Nov 9 at 12:11
I think it would be more stream-esque if you add n to the text with a separate .map call
– Tim Castelijns
Nov 9 at 8:41
I think it would be more stream-esque if you add n to the text with a separate .map call
– Tim Castelijns
Nov 9 at 8:41
I don't understand what that has to do with my comment
– Tim Castelijns
Nov 9 at 8:48
I don't understand what that has to do with my comment
– Tim Castelijns
Nov 9 at 8:48
thanks Pijotrek, your code solved my problem, why I can not vote up ?
– patel
Nov 9 at 12:11
thanks Pijotrek, your code solved my problem, why I can not vote up ?
– patel
Nov 9 at 12:11
add a comment |
up vote
1
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
Nov 9 at 16:34
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
Nov 9 at 17:26
add a comment |
up vote
1
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
Nov 9 at 16:34
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
Nov 9 at 17:26
add a comment |
up vote
1
down vote
up vote
1
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 Nov 9 at 8:50
Bsquare
2,0561828
2,0561828
thanks Bsquare, at the beginning I did not understand your solution, but it works well
– patel
Nov 9 at 16:34
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
Nov 9 at 17:26
add a comment |
thanks Bsquare, at the beginning I did not understand your solution, but it works well
– patel
Nov 9 at 16:34
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
Nov 9 at 17:26
thanks Bsquare, at the beginning I did not understand your solution, but it works well
– patel
Nov 9 at 16:34
thanks Bsquare, at the beginning I did not understand your solution, but it works well
– patel
Nov 9 at 16:34
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
Nov 9 at 17:26
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
Nov 9 at 17:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown