please help me out with this killing problem.

Status
Nicht offen für weitere Antworten.

geniusfat

Mitglied
have you guys ever tried such a thing:
Code:
System.out.println("ä".equals("?"));
my console gives me this unblievable return:
true
and if i try this:
Code:
System.out.println((Int)'ä');
it doesn't print the unicode of ä, but the unicode of "?"
I am going crazy now...
p.s. I am using eclipse on a german system, but my system-text is chinese because i've configured it. Perhaps it has something to do with this? then how could I configure eclipse to solve this problem
 

Wildcard

Top Contributor
What encoding are you using in Eclipse (and why would you even want umlauts in Source-code? :bae: )?
 
G

Gast

Gast
on my german system it prints false.
the second prints 228 and that is also right.


print out all properties:

java.util.Properties p=System.getProperties();

i bet user.language is not de
 

geniusfat

Mitglied
this is the print out of my system properties:
{java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, sun.boot.library.path=C:\Programme\Java\jre1.5.0_10\bin, java.vm.version=1.5.0_10-b03, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=CN, sun.os.patch.level=Service Pack 2, java.vm.specification.name=Java Virtual Machine Specification, user.dir=D:\eclipse\workplace\utils, java.runtime.version=1.5.0_10-b03, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Programme\Java\jre1.5.0_10\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOKUME~1\ken\LOKALE~1\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows XP, sun.jnu.encoding=GBK, java.library.path=C:\Programme\Java\jre1.5.0_10\bin;.;C:\WINDOWS\system32;C:\WINDOWS;d:\Programme\MiKTeX 2.5\miktex\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Programme\ATI Technologies\ATI Control Panel;C:\Programme\Intel\Wireless\Bin\;D:\Programme\MySQL\MySQL Server 5.0\bin;.;;D:\Programme\uDraw(Graph)\bin;d:\Programme\SSH Communications Security\SSH Secure Shell;.;D:\Programme\uDraw(Graph)\bin;D:\ghc\ghc-6.6\bin;;C:\PROGRA~1\GEMEIN~1\MUVEET~1\030625, java.specification.name=Java Platform API Specification, java.class.version=49.0, sun.management.compiler=HotSpot Client Compiler, os.version=5.1, user.home=C:\Dokumente und Einstellungen\ken, user.timezone=, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=GBK, java.specification.version=1.5, java.class.path=D:\eclipse\workplace\utils;D:\eclipse\workplace\scNew\jdom.jar, user.name=ken, java.vm.specification.version=1.0, java.home=C:\Programme\Java\jre1.5.0_10, sun.arch.data.model=32, user.language=zh, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, java.vm.info=mixed mode, sharing, java.version=1.5.0_10, java.ext.dirs=C:\Programme\Java\jre1.5.0_10\lib\ext, sun.boot.class.path=C:\Programme\Java\jre1.5.0_10\lib\rt.jar;C:\Programme\Java\jre1.5.0_10\lib\i18n.jar;C:\Programme\Java\jre1.5.0_10\lib\sunrsasign.jar;C:\Programme\Java\jre1.5.0_10\lib\jsse.jar;C:\Programme\Java\jre1.5.0_10\lib\jce.jar;C:\Programme\Java\jre1.5.0_10\lib\charsets.jar;C:\Programme\Java\jre1.5.0_10\classes, java.vendor=Sun Microsystems Inc., file.separator=\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.desktop=windows, sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86}
you are right, the user.language is not de, but zh, then how can I configure my eclipse to set it with de?
 

geniusfat

Mitglied
actually I don't want umlauts in the source code, but it refers to a communication package I wrote for my project, which would do the transporting of any kind of type, including String.
So if i have a String to send, I do the following:
Code:
	public static byte[] getByteArray(String s){
		ByteArrayOutputStream baos = new ByteArrayOutputStream(s.length()+1);
		DataOutputStream out = new DataOutputStream(baos);
		try{
			for(int i=0;i<s.length();i++){
				out.write((byte)s.charAt(i));
			}
			out.write('&');
		}catch(Exception e){
			SCLog.log(e.toString(), "common.ByteConverter.getByteArray(String)");
			return null;
		}
		return baos.toByteArray();
	}
 

geniusfat

Mitglied
as seen, the String is converted to a byte array firstly, and then I would send the byte array out.
the reason I do not send the whole string immediately is that, my communicationsmechanism should also work between different plattform, which are e.g. java and c++. If I do the transmission between java and c++, I have to reverse some types to keep the rightness of the sent value, so I firstly get a byte array, and reverse it, then send.(although it doesn't concern with String here, for String doesn't need to be reversed)
 

Wildcard

Top Contributor
It's most likely only an encoding issue in Eclipse, so check which encoding you're using for the source files from within Eclipse.
 

geniusfat

Mitglied
but to keep my whole mechanism clean and united, the converting is kept.
And the problem occurs if the String to be sent has umlaubts, probably because of the seventh line:
Code:
out.write((byte)s.charAt(i));
in my code above.
the umlaubt can't be recognized and converted with its own unicode, but to the unicode of "?".
So actually if I send "fröhlich" then I get "fr?hlich" on the other side
 

geniusfat

Mitglied
but which encoding should I choose, I 've tried all of them(UTF-8, US-ASCII...) to test my programm, but it doesn't work
 

Wildcard

Top Contributor
UTF-8 should work , so the question is where you're getting the String from and how you're converting it to a byte Array and back to String.
 

geniusfat

Mitglied
UTF-8 works, but the problem remains unsolved. because the problem is the converting from umlaubt to byte doesn't work.
which means, if i do this
Code:
System.out.println((byte)'ö');
System.out.println((int)'ö');
then i will get
Code:
-10
246
How can I solve this...
 

geniusfat

Mitglied
One solution came to my mind is, by the converting back to a string, I could practically check if it's -10, if so, i can append 'ö' into the result.
But it's totally not nice, i think...
 

Wildcard

Top Contributor
byte is in the two's complement format.
Umlauts are not in the 0..127 ASCII range and therefor you're exceding the positiv values that a byte can hold.
 

geniusfat

Mitglied
ok, then I have to do some own handling before i convert an umlaubt into byte, hope that can be solved after then;)
thanks very much for your advices ;) it helped a lot
 

Wildcard

Top Contributor
It has nothing to do with umlauts, you just cannot simply cast chars (0-255) to byte (-128-127) and expect a meaningful result.
See my posting above for the correct way to cast.
 

geniusfat

Mitglied
it would work if i convert the byte into Int and then do the addition, but that's too stupid...
oh, my basic knowledge is so bad...
:)
 
Status
Nicht offen für weitere Antworten.

Ähnliche Java Themen

Neue Themen


Oben