• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to make a £ symbol printed from a file?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am working on Solaris and facing a problem. I have a .DAT file which simply contains some data in particular format which includes £ symbol. The fomat looks like

001|£30VB | | |T+T250|£30 Value Bundle |1|1|1 |0 |0|0 | |0|1010906 |93731 |TREVORJ |CRBCE1P |1090713 |134739 |JAMESMAT |CRBCE1P |9 |1|PRE-REPORT | | |

The requirement is a java program will be reading the file and printing the same file as it is. But when my program is reading the file and printing everthing is perfectly printed except "£" symbol (read as pound). It is printing "?" instead.

Observations :
  • 1. When I am doing "cat Myfile.DAT" every thing getting displayed perfectly including £ symbol.
    2. When I am opening the same file in vi editor it is displaying ASCII value for £ symbol. (/243).
    3. I tried to change the encoding from java level by setting the property (in the program Myprog.java) like this




  • It is reading the .DAT file properly and printing properly. But the bottleneck is , we can not execute the java program from command line as a matter of fact, I tried to set the property(file.encoding) in code level by writing this:


    but this does not work. From java level I am checking, it is showing that property has been set but actually the program is not working if I do it from code level.

    How to proceed? Any ideas? Hopefully this has to be handled in java level not in Unix level (not sure).
    Just to read a dat file and print the file output using java.
    Mods, forgive me if I have posted in wrong place.
    Thanks in advance.

    Regards,
    Bhaskar
     
    Marshal
    Posts: 79178
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Java should have no difficulty printing "£". Try diverting your output; instead of using System.out, try JOptionPane.showMessageDialog(). You might need null for your first argument.
     
    Marshal
    Posts: 28193
    95
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    When you read from the file, use an InputStreamReader which specifies the encoding explicitly. (Your post implies that you are relying on the system's default encoding.) Something like this:

     
    Sheriff
    Posts: 22783
    131
    Eclipse IDE Spring VI Editor Chrome Java Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The terminal (CMD.EXE, bash, etc) usually cannot handle anything outside the ASCII charset. Using JOptionPane as Campbell suggested can get around this.
     
    Campbell Ritchie
    Marshal
    Posts: 79178
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I have no difficulty persuading bash to print £

    campbell@queeg:~$ ££
    bash: ££: command not found
    campbell@queeg:~$

    . . . even though it can't find anything to do with it. Now CMD.exe, that's something different. It prints ú instead!
     
    Bhaskar Mukhejee
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,

    well i have tried

    in order to explicitly change the encoding, but this is also not working on solaris and printing same "?" instead of

    Can you suggest me how to encode programmatically in java instead of specifying option -Dfile.encoding=ISO-8859-1 from unix.
     
    Bhaskar Mukhejee
    Greenhorn
    Posts: 14
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,

    Is Pane a good idea to implement in this case? I took strategy where each line of the file read sequentially and print it using System.out.println() there by applying the encoding explicitly as suggested,



    Set the encoding with a particular value. It worked.

    Thanks to all of you spending time and reading this post.

    Regards,
    Bhaskar
     
    Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic