Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #3504

Re: Can't display UTF-8 e

Path csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!transit3.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail
From "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this>
Subject Re: Can't display UTF-8 e
Message-ID <dMqdnZfX7Zd_G7HVRVnyjgA@bt.com> (permalink)
X-Comment-To comp.lang.java.gui
Newsgroups comp.lang.java.gui
In-Reply-To <f1be58a9-aa85-4900-a781-2ebba6655e76@8g2000hse.googlegroups.com>
References <f1be58a9-aa85-4900-a781-2ebba6655e76@8g2000hse.googlegroups.com>
Content-Type text/plain; charset=IBM437
Content-Transfer-Encoding 8bit
X-Gateway time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92]
Lines 68
Date Wed, 27 Apr 2011 15:45:16 GMT
NNTP-Posting-Host 96.60.20.240
X-Complaints-To news@tds.net
X-Trace newsreading01.news.tds.net 1303919116 96.60.20.240 (Wed, 27 Apr 2011 10:45:16 CDT)
NNTP-Posting-Date Wed, 27 Apr 2011 10:45:16 CDT
Organization TDS.net
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.gui:3504

Show key headers only | View raw


  To: comp.lang.java.gui
jgricourt@free.fr wrote:
> Your example works for me too ! But unfortunately this is not what I
> am trying to do. I got a text string from a UTF-8 encoded file and
> after reading the file I set a String with the text content in order
> to display in a JLabel.
> 

Your Google-fu is too weak! Exercise it more!

--------------------------- 8< ---------------------------------
class CharacterEncodingTest {

     static final String FILENAME = "foo.txt";

     public static void main(String[] args) {
         try {
             writeMyUtf8File(FILENAME, "|-|-|-|-|-");
             final String text = readMyUtf8File(FILENAME);
             SwingUtilities.invokeLater(new Runnable() {
                 public void run() {
                     new CharacterEncodingTest(text);
                 }
             });
         } catch (IOException e) {
             e.printStackTrace();
         }
     }

     static void writeMyUtf8File(String name, String text)
             throws IOException {
         FileOutputStream fos = new FileOutputStream(name);
         Writer osr = new OutputStreamWriter(fos, "UTF-8");
         osr.write(text);
         osr.close();
     }

     static String readMyUtf8File(String name) throws IOException {
         FileInputStream fis = new FileInputStream(FILENAME);
         InputStreamReader isr = new InputStreamReader(fis, "UTF8");
         BufferedReader br = new BufferedReader(isr);
         String text = br.readLine();
         br.close();
         return text;
     }

     CharacterEncodingTest(String text) {
         JPanel p = new JPanel();
         p.add(new JLabel(text));

         JFrame f = new JFrame("Char Encoding Test");
         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         f.add(p);
         f.pack();
         f.setLocationRelativeTo(null);
         f.setVisible(true);
     }
}
--------------------------- 8< ---------------------------------


-- 
RGB

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Can't display UTF-8 e "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
  Re: Can't display UTF-8 e "jgricourt" <jgricourt@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
    Re: Can't display UTF-8 e "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
    Re: Can't display UTF-8 e "tar" <tar@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
    Re: Can't display UTF-8 e "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
      Re: Can't display UTF-8 e "jgricourt" <jgricourt@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000

csiph-web