1

Topic: The people and how to write to a file in different codings?

It is necessary to write to a file in coding DOS|WIN.
How it to make?

2

Re: The people and how to write to a file in different codings?

Look OutputStreamWriter - there is .
And here is how to write in the mixed coding - straight off and I do not know sad.  on docks - it is similar Sun considers that it is not necessary, and? smile

3

Re: The people and how to write to a file in different codings?

It is possible so: opened-wrote down-closed, replaced the coding-added.

4

Re: The people and how to write to a file in different codings?

LSD, 12/6/2004, 21:24 wrote:

It is possible so: opened-wrote down-closed, replaced the coding-added.

Simply perfectly well!
And present that . On a grid, what alternation hardly-whether not through 10 byte what it is necessary to be returned and add?
Not, I do not know - therefore so interesting.

5

Re: The people and how to write to a file in different codings?

There is still a variant: to encode a line in an array byte, for example: Sting.getBytes (<the coding>) and to write immediately them.

6

Re: The people and how to write to a file in different codings?

And it is possible any ????

7

Re: The people and how to write to a file in different codings?

FileOutputStream out = new FileOutputStream ("multiencodedfile.txt");
out.write ("The Line in CP1251\n".getBytes ("CP1251"));
out.write ("The Line in UTF-8\n".getBytes ("UTF-8"));
out.close ();

8

Re: The people and how to write to a file in different codings?

To write in different codings to a file - a question in itself it is not correct.
Actually the coding designates what type the character replaces that  byte which to be stored in a file. It is possible to read it as one coding, and another. Absolutely on a drum.
LSD similar offered the best idea - before a piece to write down value of the coding and at reading this value to consider.

9

Re: The people and how to write to a file in different codings?

It turned out, thanks.

FileOutputStream out = new FileOutputStream ("multiencodedfile.txt");
out.write ("The Line in CP866\n".getBytes ("CP866"));
out.close ();

Here only a small problem: line feed (\n) in CP866 has a HEX-code 0A
And it is necessary that was 0D 0A
How it to make?

10

Re: The people and how to write to a file in different codings?

Means before writing in this coding it is necessary to provide, that it was written so - to replace that is, pens, fairly.

11

Re: The people and how to write to a file in different codings?

The HEX-code 0A '\n ' is newline or Line feed
The HEX-code 0D '\r ' is carriage return or Carriage return.
These are two different actions, their codes are standard for all codings as they concern the auxiliary characters.
Therefore it is possible to write

out.write ("The Line in ljubaja_kodirovka\n\r".getBytes ("_"));

Or

out.write ("The Line in ljubaja_kodirovka\r\n".getBytes ("_"));

- And it is fair, and to pens it is possible to have a rest:D
Carriage return '\r ' as independent action already is not used and is actual only for DOS applications.
However if the word-processor interprets '\r ' as '\n ' - he will add superfluous blank line.

LSD similar offered the best idea - before a piece to write down value of the coding and at reading this value to consider.

Idea LSD really true, but I do not absolutely agree with the comment:
Value of the coding there is no need to write down and consider (yes it and does not register in an output flow). When on the screen the chain of bytes "D1 F2 F0 EE EA E0" is displayed in a readable type ("Line") is because the current coding of application - Win1251. At coding change we see abracadabra though the chain of bytes does not change. And here when in

"Line".getBytes ("CP866")

We specify other coding, the chain of bytes and in this changed type it will change and will be written down in a file. In a file thus no information on the coding WILL exist!
I ask to excuse me for verbosity, but here wrote - and most it became more clear smile

12

Re: The people and how to write to a file in different codings?

Thanks for the help.:D

13

Re: The people and how to write to a file in different codings?

The same sense, only case on the contrary, from a file
There is a code at me

static final String ENCODING = "koi8-r";
...
java.io. BufferedReader reader = null;
try {
reader = new java.io. BufferedReader (new java.io. InputStreamReader (new java.io. FileInputStream ("C:/..../Queryes /" + name), ENCODING));
java.util. ArrayList <String> list = new java.util. ArrayList <String> ();
while (reader.ready ())
list.add (reader.readLine ());
reader.close ();
for (String line: list)
query = line;
} catch (java.io. FileNotFoundException e) {
javax.swing.JOptionPane.showMessageDialog (this, e, "Error", javax.swing. JOptionPane. ERROR_MESSAGE);
} catch (java.io. IOException e) {
javax.swing.JOptionPane.showMessageDialog (this, e, "Error", javax.swing. JOptionPane. ERROR_MESSAGE);
}

Earlier generally ENCODING did not add, but also it does not help to read out normally from a file Russian letters.
There is a variant certainly  a line

reader = new java.io. BufferedReader (new java.io. InputStreamReader (new java.io. FileInputStream ("C:/..../Queryes /" + name), ENCODING));

But what then instead it is better to use?
Or can read out somehow byte by byte type getBytes ......
it is a lot of thoughts but how to implement better in meditations???

14

Re: The people and how to write to a file in different codings?

Bulat, 11/30/2006, 11:37, post942260 wrote:

Voobshchem of thoughts is a lot of but how to implement better in meditations???

It certainly is good, but  accurately to hear in what the problem? Errors, the Russian text is read  or still that?

15

Re: The people and how to write to a file in different codings?

LSD , , I understood, here at all in it put was, simply attentiveness in one trifle most did not suffice smile

16

Re: The people and how to write to a file in different codings?

And it is valid, what for to write to a file in different codings? How it then to read? Whence it will be possible to learn, what coding in the given specific place ?

17

Re: The people and how to write to a file in different codings?

Dims, 12/3/2006, 06:42, post945580 wrote:

And it is valid, what for to write to a file in different codings?

Personally I had a necessity to store requests to a DB in a file that each new time not to inscribe ;-) but in request figured ... like' % '

Dims, 12/3/2006, 06:42, post945580 wrote:

As it then to read?

Look above, like at me just  the code where reads out the data from a file, and it really works, there at me  was absolutely in other.... One of variants