#How to write a file in ANSI

34 messages · Page 1 of 1 (latest)

sinful palm
#

I need to write a file in ANSI encoding, but no matter what I'll try it always ends up in UTF-8.

I tried using the OutputStreamWriter and passing "Cp1252" or "Window-1252" but it didn't work.

finite rootBOT
#

This post has been reserved for your question.

Hey @sinful palm! Please use /close or the Close Post button 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.

floral ice
#

(though that windows-1252, ending with an S)

finite rootBOT
#

💤 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.

sinful palm
#

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

floral ice
sinful palm
floral ice
#

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

sinful palm
floral ice
#

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

sinful palm
#
            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

sinful palm
sinful palm
floral ice
#

? 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

sinful palm
#

so it could be a problem with reading the ANSI?

floral ice
#

Sounds like it, if your text comes from reading an ANSI file

sinful palm
#
        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

floral ice
#

That looks correct, yes. I'd need some examples to work with

sinful palm
#

of the ANSI file?

floral ice
#

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

sinful palm
#

or is there some settings inside maven i need to change?

floral ice
#

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

sinful palm
#

I just dont unterdand why its workink in the IDE but not in jar

sinful palm
#

The test programm works fine... hidethepain

finite rootBOT
#

💤 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.