I implemented a code that takes input file from command line. Then, sorts this input. Then write output to current directory. My code works but I am wondering that type of file. My input.txt type is dos\Windows as seen in the picture. My generated output.txt type is UNIX. Also their sizes are different. Why are they stored in different format? I used, bufferedReader, fileWriter to implement this code.
code.java:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.io.FileWriter;
public class code{
public static void main(String[] args) {
try (BufferedReader br = new BufferedReader(new FileReader(args[0])))
{
int lines = 0;
while (br.readLine() != null) lines++; // to get text's number of lines
String sCurrentLine;
BufferedReader br2 = new BufferedReader(new FileReader(args[0])); //to read and sort the text
String[] array; //create a new array
array = new String[lines];
int i=0;
while ((sCurrentLine = br2.readLine()) != null) {//fill array with text content
array[i] = sCurrentLine;
i++;
}
Arrays.sort(array); //sort array
FileWriter fw = new FileWriter("output.txt");
for (i = 0; i < array.length; i++) { //write content of the array to file
fw.write(array[i] + "\n");
}
fw.close();
System.out.println("Process is finished.");
} catch (IOException e) {
e.printStackTrace();
}
}
}
input.txt:
x a t f a s f g h j n v x z s d f g b s c d e d d
output.txt :
a a b c d d d d e f f f g g h j n s s s t v x x z
How can I generate output file as windows format(Also,their sizes should be same)?


\n; while on DOS/Windows it is\r\n.