i have a software that creates a file which i send to a bank software that reads the file.
But this software is rejecting my file because it says my file does not have CRLF
as line separator.
Until now, the file was only created on windows machines, and for line separator i use always "\r\n"
.
I searched about it and found out that if i do it on windows, it generates in a different way than generating on linux or mac.
But how can i always generate CRLF
independent of platform?
UPDATE 1
This is the method i use to create the file, i replace all \r\n for \n and then \n to \r\n, just to ensure that when whoever calls this method passing only \n as line separator, the file will be generated correctly with \r\n:
public static void createFile(String filePath,String content){
try{
File parentFile=new File(filePath).getParentFile();
if(parentFile!=null && !parentFile.exists()){
parentFile.mkdirs();
}
BufferedWriter bw=new BufferedWriter(new FileWriter(filePath));
bw.write(content.replaceAll("\r\n","\n").replaceAll("\n","\r\n"));
bw.flush();
bw.close();
}catch(Exception e){
throw new RuntimeException("Error creating file", e);
}
}