not able to sort textfile input line by line in an output file
up vote
1
down vote
favorite
I ran into a problem. I have written following program to sort string of integers in a text file and output the sorted list of integers in an output file. The input file can contain multiple lines of integers and I want to sort them one line at a time and print it out in my output file.
The problem is program reads all the lines from input text and prints out a continuous line of sorted numbers in the output file. How do I make program sort and print sorted list line by line in output file ?
import java.util.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class MergeSort
up vote
1
down vote
favorite
I ran into a problem. I have written following program to sort string of integers in a text file and output the sorted list of integers in an output file. The input file can contain multiple lines of integers and I want to sort them one line at a time and print it out in my output file.
The problem is program reads all the lines from input text and prints out a continuous line of sorted numbers in the output file. How do I make program sort and print sorted list line by line in output file ?
import java.util.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class MergeSort improve this answer
add a comment
outFile.close();
You are missing println. Snippet:
for (int i = 0; i <= intarray.length - 1; i++)
outFile.print(intarray[i] + " ");
outFile.println(); // this is missing
}
outFile.close();
answered Nov 11 at 1:28
muradm
717419
717419
add a comment |
add a comment |
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%2f53244996%2fnot-able-to-sort-textfile-input-line-by-line-in-an-output-file%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