2

I'm trying to use the following Spanish characters in the command line in NetBeans (using Java):

a á e é i í o ó u ú A Á E É I Í O Ó U Ú Ñ ñ

However when I enter this line, I got the following result:

a � e � i � o � u � A � E � I � O � U � � �

The code I'm using is:

public class SpanishChars {

public static void main (String[] args)
{
    Scanner sc = new Scanner(System.in);

    System.out.println("Enter some spanish chars next: ");
    String spanishLine = sc.nextLine();

    System.out.println("Spanish char entered are next: " + spanishLine);
}

I know it's a NetBeans problem because when I run same program in Eclipse IDE, results are just fine.

Does any one know how to fix it?

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
MauricioTL
  • 343
  • 1
  • 5
  • 17
  • This is possibly just an issue with the font used by the output window – MadProgrammer May 28 '14 at 03:00
  • Or some encoding support which netbeans does not default. I dont use netbeans right now, so I cant solve your problem. but try to change some encoding settings, try to set UTF-8. these might solve the problem. – guness May 28 '14 at 03:02
  • I would recommend to print all system.properties in java and check what is the current encoding is used. Else need to set in OS environment – UVM May 28 '14 at 03:07
  • 1
    With your feed back I have checked encoding setings and is set to UTF-8, also I have printed system.properties in java and result is: file.encoding=UTF-8. I think is a direct NetBens trouble since same program runs fine in Eclipse IDE. Any othe suggestion?. Thank you!! – MauricioTL May 28 '14 at 03:28
  • @MauricioTL Take a look at this link http://wiki.netbeans.org/FaqI18nProjectEncoding I could not figure it out; lets see whether you can – Kick Buttowski May 28 '14 at 03:50
  • 1
    Bienvenido a StackOverflow :-) While "siguiente" does mean "next", in this context the idiomatic translation is "following" (or possibly "below"). I edited it for you. – Jim Garrison May 28 '14 at 04:08

2 Answers2

2

I was playing in Netbeans 8, and I found out when I change encoding to ISO-8859-9 and run the code, the out come is going to be

Enter some spanish chars next: 
a á e é i í o ó u ú A Á E É I Í O Ó U Ú Ñ ñ
Spanish char entered are next: a á e é i í o ó u ú A Á E É I Í O Ó U Ú Ñ ñ

Note: To change encoding inside Netbenas 8 IDE: click on your node project-> right click -> click on properites-> click on source -> change encoding section

Kick Buttowski
  • 6,709
  • 13
  • 37
  • 58
  • I have tried same direction as above in NetBeans 7.4 but doesn't work, I will update to NetBeans 8 and let you know. Thanks!! – MauricioTL May 28 '14 at 15:18
  • 1
    Hi Buttowski, doing a little more research found next solution, which is also good and no upgrade of netbeans is nedeed. http://stackoverflow.com/questions/5922845/how-to-display-utf8-in-netbeans-7 Thank you!!! @Kick Buttowski – MauricioTL Jun 04 '14 at 20:49
  • @mauriciotl, I tried to solve this by coding but I couldn't take a look at my post http://stackoverflow.com/questions/23904391/why-different-answer-from-same-string/23923431?noredirect=1#comment36876053_23923431 – Kick Buttowski Jun 09 '14 at 00:37
  • I see you still have issues with Scanner Classs. Why don't you try running your Java Program in Eclipse IDE?, I had same trouble and by running in Eclipse, I could realize it should be a NetBeans trouble IDE (because in Eclipse there was no trouble), not java clases or the Operative system. Does it work?? @Kick Buttowski – MauricioTL Jun 09 '14 at 17:33
  • Additionally the line I have moddified in the following archive: C:\Program Files\NetBeans 7.4\etc\netbeans.conf is: netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true -J-Dfile.encoding=UTF-8" and to be exact the statement I added is (the last one) : -J-Dfile.encoding=UTF-8 – MauricioTL Jun 09 '14 at 18:48
0

Doing the following finally work in my NetBeans Project.

1) Adding folowwing code at begining of jsp page:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>

2) Adding in head section of same page:

 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

Hope it helps for someone else.

MauricioTL
  • 343
  • 1
  • 5
  • 17