6

As title says, I'm using Netbeans 8.0.2, on Windows 7 OS. I saw many different topics about this and tried different solutions, but none really helped.

So characters like [š, ć, đ, ž, È, æ] are displayed as � or squared, depending on the font. Here is what I've tried:

  • I have set -J-Dfile.encoding=UTF-8 in ../etc/netbeans.conf
  • I've checked project settings and encoding is set to utf-8

enter image description here

  • When I'm reading file, I'm using following code:

    BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); or with Charset.forName("UTF-8") or StandardCharsets.UTF_8 or Charset.forName("ISO8859-2") nothing helped.

Any one has idea what other problem could be ?

Kapparino
  • 988
  • 11
  • 33
  • What character encoding set is your OS using? Have you tried setting it to `en_US.UTF-8`? – pietv8x Aug 04 '15 at 16:50
  • How can I check it in Windows 7 if is set to it ? – Kapparino Aug 04 '15 at 16:55
  • Check the control panel somewhere like here: control panel / system / advanced system settings / advanced / environmental variables – pietv8x Aug 04 '15 at 16:56
  • That's not a solution. – Kapparino Aug 04 '15 at 17:16
  • 3
    Where, and how, are these characters displayed? – JB Nizet Aug 04 '15 at 17:27
  • The location matters. I've been doing a data parsing project lately and UTF characters display differently depending on the stage of the process through different programs. I believe in JavaFX TextFields some of them come up as a similar null-character. If it's in NetBeans itself, it could be a problem at the OS level, if it varies between applications, it could be NetBeans, if it's in output fields for a program, could be local to that instead. – Captain Prinny Aug 04 '15 at 17:37
  • @JBNizet In Java Console Application, in output. – Kapparino Aug 04 '15 at 19:31
  • 2
    Maybe you should provide a small piece of code which demonstrate your problem. What does `System.out.println("\u0161");` print on your console? (should be š). – SubOptimal Aug 07 '15 at 06:33
  • `System.out.println("\u0161");` prints š. About a small piece of code, it is nothing else than a `while ((line = bufferedReader.readLine()) { sout(line)... }` – Kapparino Aug 07 '15 at 08:47
  • are you sure the read is OK? I've installed netbeans and ran a simple sample application and all characters are printed as expected with the default settings. – Olimpiu POP Aug 12 '15 at 13:34

3 Answers3

3

I have found out that this characters [š, ć, đ, ž, È, æ] are type Eastern European (Windows-1250).

So the correct encoding type is "Windows-1250".

Kapparino
  • 988
  • 11
  • 33
3

That's not a Netbeans issue per se, The netbeans FileAPI can open files in any encoding. When you don't know what encoding to use you can use this plugin to change the encoding dinamically.

Update: you can find the plugin now in the official plugins page as Encodding Support

Ruslan López
  • 4,433
  • 2
  • 26
  • 37
2

To read text file with UTF-8 encoding use this code (Java 8):

BufferedReader br = new BufferedReader(new InputStreamReader(
                new FileInputStream(file), StandardCharsets.UTF_8
        ));

To find file encoding use one of encoding detectors: What is the most accurate encoding detector?

To set encoding for your program source code use this settings:

  • Netbeans

    [project settings] / source / encoding = UTF-8
    
  • Maven:

    <project>
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
    </project>
    
Community
  • 1
  • 1
kinjelom
  • 6,105
  • 3
  • 35
  • 61