#How to write a file in ANSI
34 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @sinful palm! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
That's normally the right way. Show exactly what you did
(though that windows-1252, ending with an S)
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use/help ping.
Warning: abusing this will result in moderative actions taken against you.
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "Cp1252");
BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
bufferedWriter.write(line);
bufferedWriter.newLine();
bufferedWriter.close();
If i run it in intellij it creates a file in ANSI but if i use maven to create a jar it ends up in UTF-8
how do you know that it is utf-8?
Notably, I see you're writing in append mode. Appending codepage1252 text won't remove the existing utf-8 text
open it with Notepad++ and the basic editor
The well-known basic editor. And what did you find with them, how, and how come you didn't address my remark about append mode.
Last time I try pulling facts from you
I try a diffrent aproch with appand false
I guess it's cheaper than finally showing what you did. Well, in the event that it was the issue all along, you'll have spared yourself doing it I guess
if (line.matches("(.*)x1 := 0;")){
System.out.println("MATCH");
line = " x1 := 0;\n"+
" Haube_Rover_C9 := 1;*VAR*";
}
if (line.matches("CALL ROVER_MC_PLC_Hauben_Pos \\( VAL POS:=\\d+\\)")){
toolline = br.readLine();
if (toolline.matches("WZ[F|S|B] (.*)")){
line = replace(line,toolline);
}
else {line = replace(line);}
}
boolean test = new File("\\Neu"+path).mkdirs();
text.append(line).append("\n");
}
FileOutputStream fileOutputStream = new FileOutputStream(userDirectory+"\\Neu"+ path,false);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "Cp1252");
BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
bufferedWriter.write(String.valueOf(text));
bufferedWriter.newLine();
bufferedWriter.close();
i thought if the file is created new it should work with appand true, currently i try to use Stringbuilder to edit my file and then write it at once
Its only working if i run it insite Intellij after creating a jar the new file ends up un UTF8 even if its created new
The umlauts are replaced with a "?" And in the lower right corner notepad tells me it's UTF-8
? isn't the normal way to demonstrate an encoding incompatibility, notably not with Notepad++
Text editors can't tell what's the encoding of a file. They tell you what encoding they're currently using. You know it's correct when it displays without error, and you know what encoding is the right one by trying them until one has no errors
It looks to me like your umlauts were corrupted and replaced with ? before you got to that point, and then the ? was written in the file
so it could be a problem with reading the ANSI?
Sounds like it, if your text comes from reading an ANSI file
BufferedReader br = new BufferedReader(new InputStreamReader(fIS,"Cp1252"));
but isnt this the correct way of reading it, i thougt it was simply the opposide of the writing process
That looks correct, yes. I'd need some examples to work with
Hmm. It looks to me like you're doing everything right. I'll have to do some tests, but it seems that something else is amiss
In the meantime I encourage you to make a very small and trivial program that reads an ANSI file, displays the text and the bytes it contains, and writes it back.
You'll see that this way to read and write the files is the right one
I just dont unterdand why its workink in the IDE but not in jar
ill do
The test programm works fine... 
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use/help ping.
Warning: abusing this will result in moderative actions taken against you.
