How to read Chinese word from a TXT file

File.OpenText() read a TXT File with  Chinese word in   ;but it not show right.
exam:The TXT File include :中国
 this.Txt1.Text=ofd.File.OpenText().ReadToEnd();
but it show :��ʹ�ݼƻ��
How to solve it

What encoding does the text file use?  Unlike .NET, Silverlight only supports UTF-8 and UTF-16.  File.OpenText() uses UTF-8 by default.
If the text file is in some other encoding, you can create your own encoding class (that derives from System.Text.Encoding) that can be used to read the text file.
class MyEncoding : System.Text.Encoding {
this.Txt1.Text = (new StreamReader(ofd.File.OpenRead(), new MyEncoding())).ReadToEnd();
Regards,
Justin Van Patten
Program Manager
Common Language Runtime

Similar Messages

  • How to read last line from a .txt file?

    Hello
    I have a string: e.g. "my name is John"
    and i wanna verify if this string is equal with the last line from a text file
    for example, if in the txt file i have:
    asdasd
    sdgsdfgasd
    asdfgadfgadf
    sdgasdgsdf
    my name is john
    then it's OK.
    but if i have
    asdgsdfg
    dsfhsdfhsd
    sdgasdfg
    sdgsdg
    my name is Jdfgsdg
    this is not correct
    How should i do this?
    Thanks:)

    Read from the beginning an discard all lines (if you have a small file), or use RandomAccessFile and scan from the end till you find the beginning of the last line.
    Kaj

  • How to read partcicular line from a txt file

    in a text file let there be 50 lines
    while reading the line if the line is having "name" as a string in that line then i have to store the next two consecutive lines in a string as array....
    Similar way and so on......
    How can we do this....

    You need a BufferedReader:
    http://java.sun.com/j2se/1.4.2/docs/api/java/io/BufferedReader.html
    for example:try {
        BufferedReader br = new BufferedReader(new FileReader("myfile.txt"));
        String line;
        while ( (line=br.readLine()) != null ) {
         if (line.indexOf("name") != -1) {
             // Store the next two lines.
             // You will need to call br.readLine() again.
    } catch (IOException x) {
        x.printStackTrace();
    }

  • I have a VI and an attched .txt data file. Now I want to read the data from the .txt file and display it as an array in the front panel. But the result is not right. Any help?

    I have a VI and an attched .txt data file. Now I want to read the data from the .txt file and display it as an array in the front panel. But the result is not right. Any help?
    Attachments:
    try2.txt ‏2 KB
    read_array.vi ‏21 KB

    The problem is in the delimiters in your text file. By default, Read From Spreadsheet File.vi expects a tab delimited file. You can specify a delimiter (like a space), but Read From Spreadsheet File.vi has a problem with repeated delimiters: if you specify a single space as a delimiter and Read From Spreadsheet File.vi finds two spaces back-to-back, it stops reading that line. Your file (as I got it from your earlier post) is delimited by 4 spaces.
    Here are some of your choices to fix your problem.
    1. Change the source file to a tab delimited file. Your VI will then run as is.
    2. Change the source file to be delimited by a single space (rather than 4), then wire a string constant containing one space to the delimiter input of Read From Spreadsheet File.vi.
    3. Wire a string constant containing 4 spaces to the delimiter input of Read From Spreadsheet File.vi. Then your text file will run as is.
    Depending on where your text file comes from (see more comments below), I'd vote for choice 1: a tab delimited text file. It's the most common text output of spreadsheet programs.
    Comments for choices 1 and 2: Where does the text file come from? Is it automatically generated or manually generated? Will it be generated multiple times or just once? If it's manually generated or generated just once, you can use any text editor to change 4 spaces to a tab or to a single space. Note: if you want to change it to a tab delimited file, you can't enter a tab directly into a box in the search & replace dialog of many programs like notepad, but you can do a cut and paste. Before you start your search and replace (just in the text window of the editor), press tab. A tab character will be entered. Press Shift-LeftArrow (not Backspace) to highlight the tab character. Press Ctrl-X to cut the tab character. Start your search and replace (Ctrl-H in notepad in Windows 2000). Click into the Find What box. Enter four spaces. Click into the Replace With box. Press Ctrl-V to paste the tab character. And another thing: older versions of notepad don't have search and replace. Use any editor or word processor that does.

  • Populate a table reading the data from a TXT file

    how can I populate a table reading the data from a TXT file?
    thanks

    Hey Kevin!
    Using FORMS.TEXT_IO to bulk load data from a file strikes me as re-inventing the wheel. It is just about justifiable in a self-service environment, but I regard the EXTERNAL TABLE is a better solution for that situation as well.
    The same applies to UTL_FILE. I think the ability to read text with UTL_FILE is primarily intended for read file-based configuration or file manipulation/processing rather than data loading.
    Re-writing a text file into SQL statements is too much like hard work (even with an editor that supports macro definition and regular expressions) for no real benefit. You lose all the bulk load peformance you would get from SQL*Loader. But for QAD I'd probably let you off with it.
    You missed out one obvious alternative: using Java to turn the contents of an XML file into a CLOB and inserting it into a table which is read by a PL/SQL procedure that parses the XML records and insert the retrieved data into a table.
    Stay lucky, APC

  • What is the 'quickest' way to read char data from a txt file

    Hello,
    What is the 'quickest' way to read character data from a txt file stored on the phone to be displayed into the screen?
    Regards

    To be even a bit more constructive...
    Since J2me does not have a BufferedInputStream, it will help to implement it yourself. It's much faster since you read large blocks at ones in stread of seperate chars.
    something line this lets you read lines very fast:
      while ( bytesread < filesize ) {
             length = configfile.read( buff, 0, buff.length );
             // append buffer to temp String
             if ( length < buff.length ) {
                byte[]  buf  = new byte[length];
                System.arraycopy( buff, 0, buf, 0, length );
                tmp.append( new String( buf ) );
             } else {
                tmp.append( new String( buff ) );
             // look in tmp string for \r\n
             idx1 = tmp.toString().indexOf( "\r\n" );
             while ( idx1 >= 0 ) {
                //if found, split into line and rest of tmp
                line = tmp.toString().substring( 0, idx1 );
             /// ... do with it whatever you want ... ////
                tmp = new StringBuffer( tmp.toString().substring( idx1 + 2 ) );
                idx1 = tmp.toString().indexOf( "\r\n" );
             bytesread += length;
          }

  • How to read every line from a text file???

    How can i read every line from my text file ("eka.txt")
    now it only reads the first line and prints it out.
    What is wrong with this?
    import java.io.*;
    import java.util.*;
    class Testi{
         public static void main(String []args)throws IOException {
         BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
    File inputFile = new File ("eka.txt");
    FileReader fis =new FileReader(inputFile);
    BufferedReader bis = new BufferedReader(fis);
    String test=bis.readLine();
    String tmp= "";
    while((bis.readLine().trim() != null)) {
    int spacefound=0;
    int l=test.indexOf(" ");
         for(int i=0;i<test.length();i++){
         char c=test.charAt(i);
         if(c!=' ') tmp+=""+c;
         if(c==' ' && (spacefound<1) && !(tmp.equals(""))){
         tmp+=""+c;
         spacefound++;
         if(tmp.length()==l) {
         System.out.println(tmp);
         tmp="";
         spacefound=0;
         if(tmp.length()<l){
         for(int i=0;i<=(l-tmp.length());i++)
         tmp+=""+' ';
         System.out.println(tmp);

    Try this code, Hope it servers your purpose.
    import java.io.*;
    import java.util.*;
    class Testi {
         public static void main(String []args)throws IOException {
              BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
              File inputFile = new File ("Eka.txt");
              FileReader fis =new FileReader(inputFile);
              BufferedReader bis = new BufferedReader(fis);
              String test=bis.readLine();
              while(test != null) {
                   StringTokenizer st = new StringTokenizer(test," ");
                   while(st.hasMoreTokens())
                        System.out.println(st.nextToken());
                   test = bis.readLine();
    }Sudha

  • How to read some lines from a text file using java.

    hi,
    i m new to java and i want to read some lines from a text file based on some string occurrence in the file. This file to be read in steps.
    we only want to read the file upto the first Occurrence of "TEXT" string.
    How to do it ,,,
    Kinldy give the code
    Regards,
    Sagar
    this is the text file
    dfgjdjj
    sfjhjkd
    ghjkdg
    hjkdgh TEXT
    ikeyt
    ujt
    jk
    tyk TEXT
    rukl
    r

    Hendawy wrote:
    Since the word "TEXT" is formed of 4 letters, you would read the text file 4 bytes by four bytes. Wrong on two counts. First, the file may not be encoded 1 byte per character. It could be utf-16 in which case it would be two byte per character. Second, even if it were 1 byte per character, the string "Text" may not start on a 4 byte boundary.
    Consider a FileInputStream object "fis" that points to your text file. use fis.read(byte[] array, int offset, int len) to read every four bytes. Convert the "TEXT" String into a byte array "TEXT".getBytes(), and yous the Arrays class to compare the equality of the read bytes with your "TEXT".getBytes()Wrong since it relies on my second point and will fail when fis.read(byte[] array, int offset, int len) does not read 4 bytes (as is no guaranteed to). Check the Javadoc. Also, the file may not be encoded with the default character encoding.
    The problem is easily solved by reading a line at a time using a BufferedReader wrapping an InputStreamReader wrapping a FileInputStream and specifying the correct character encoding.
    Edited by: sabre150 on Apr 29, 2009 2:13 PM

  • How to read iCal events from SQLite Cache file?

    I need to figure out how to read event entries in the Cache file stored in /Library/Calenders/ as my actual events have been corrupted due to a file system problem. The example below shows the information I have for each entry, where the event in the entry was Bon Jovi Concert, however I am confused how I can read the date and time of the event, information I believe is stored as 218215639,219613081,219524400,219540600. Any help is greatly appreciated.
    INSERT INTO "ZCALENDARITEM" VALUES(0,NULL,0,NULL,0,5,NULL,6,4039,NULL,0,0,0,0,0,0,2,23,0,0,0,0,6,0,21821563 9,219613081,219524400,219540600,NULL,NULL,NULL,NULL,NULL,'local_AFB8D342-2DAE-4F A1-A9A6-3FA9B28B5C7C','Bon Jovi Concert',NULL,NULL,NULL,'Europe/London',NULL,'0E17BBB6-0E76-4024-8DD7-60E43D38D 35B');

    OK, here we go ... I hope. I have tried it on my iCal, with about 2000 entries, and it worked. I cannot guarantee that it will work for you.
    Make a new text file from sql as before, but using this modified command to get additional data for each event:
    sqlite3 Desktop/Hope 'select ZSTARTDATE, ZCALENDARITEM.ZTITLE, ZENDDATE, ZNODE.ZTITLE, ZISALLDAY, ZRECURRENCERULE, ZISDETACHED from ZCALENDARITEM inner join ZNODE on ZCALENDARITEM.ZCALENDAR = ZNODE.Z_PK where ZSTARTDATE not null' >hope.txt
    I suggest you make a new user account, then copy the text file hope.txt and the script to the Public/Drop Box folder for that account. Log on to the new account and copy the two files from the drop box to the Desktop. Start iCal and make new calendars to match those in your ordinary account. Double click the script to open it in Script Editor and CHANGE THE DATE RANGE in the "set ThePeriod" line. Stand well back and click the run button. Every 50 records processed it will pop up a progress box, which will pop down again after a second. Go for lunch.
    When it is finished see if things look OK in iCal. If they do export each of the calendars, copy them to the drop box of your normal account and return to your normal account to import them.
    If there is an error make a note of the error message and line number, find that line in the text file, and post it here with a couple of lines either side.
    Note that for recurring items iCal normally only makes a single event, the first occurrence, then uses a recurrence rule to calculate if the event should be displayed in the current window. If there are any recurring events in the period you have selected where the first occurrence is before the period they will not be recreated. Where however you have changed a single occurrence of a recurring event iCal makes a new, detached, event. Any of these in the period will be detected. If their original event was also in the period they will now appear in the iCal display as duplicates. For easy spotting of these, I have prefixed "XX-" to the title of any detached events.
    AK
    <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">on run
    set ThePeriod to {date ("jan 1 2008"), date ("dec 31 2008")} --CHANGE THIS BEFORE RUNNIN
    set TheFile to open for access (path to desktop as text) & "temp.txt"
    set TheContents to read TheFile --until return
    close TheFile
    set TheLines to paragraphs of TheContents
    set OldDelim to AppleScript's text item delimiters
    set AppleScript's text item delimiters to {"|"}
    set LCount to 0
    set ACount to 0
    set RCount to 0
    set DCount to 0
    set SCount to 0
    set HowMany to (count of TheLines)
    try
    repeat with ThisLine in TheLines
    if (count of ThisLine) is 0 then exit repeat
    -- Start Date, Title, End Date, Calendar, All Day, Recurs, Detached
    set LCount to LCount + 1
    set Details to text items of ThisLine
    set MyStartDate to FixMyDate(item 1 of Details)
    set MyTitle to item 2 of Details
    set MyEndDate to FixMyDate(item 3 of Details)
    set MyCalendar to item 4 of Details
    set MyAllDay to item 5 of Details
    set MyRecurs to item 6 of Details
    set MyDetached to item 7 of Details
    if MyAllDay is "1" then set ACount to ACount + 1
    if (count of MyRecurs) > 0 then set RCount to RCount + 1
    if MyDetached is "1" then set MyTitle to "XX-" & MyTitle
    if MyDetached is "1" then set DCount to DCount + 1
    if (MyCalendar is not "Birthdays") and (MyStartDate ≥ item 1 of ThePeriod) and (MyStartDate ≤ item 2 of ThePeriod) then
    tell application "iCal"
    tell calendar MyCalendar
    set ThisItem to make new event at end of events with properties {summary:MyTitle, start date:MyStartDate}
    end tell
    tell ThisItem
    if MyAllDay is "1" then set allday event to true
    if (count of MyRecurs) > 0 then set recurrence to MyRecurs
    set end date to MyEndDate
    end tell
    end tell
    else
    set SCount to SCount + 1
    end if
    if (LCount mod 50) = 0 then
    set the_message to "Processed " & (LCount as string) & " of " & (HowMany as string)
    display dialog the_message buttons {"Cancel"} giving up after 1
    end if
    end repeat
    on error TheError
    display dialog "Error: " & TheError & " about line " & LCount
    end try
    set AppleScript's text item delimiters to OldDelim
    display dialog (LCount as string) & " lines processed" & return & "All Day: " & (ACount as string) & return & "Recurs: " & (RCount as string) & return & "Detach: " & (DCount as string) & return & "Skipped: " & (SCount as string)
    end run
    on FixMyDate(MyDate)
    date (do shell script "date -r " & MyDate & " -v+31y +%e'/'%m'/'%y' '%T")
    end FixMyDate
    </pre>

  • How to read configuration data from an xml file (not web.xml)?

    Hi,
    I want to separate the application specific configuration parameters in a separate xml file and read them as and when they are needed? I know that I can use the wb.xml but I want to separate them in a different xml file because I don't want the web.xml file to be played around later after deployment. If any change is needed then it should be done in the application-config.xml.
    How can I read the parameters from this xml file in my jsp code and also what should be the location of this file if I have
    ../webapps/Root/application
    directoty structure ?
    Any help is greatly appreciated.

    can you give an example of a property file and also
    it is loaded in the jsp ?Hmm... loading properties in a JSP is not a very good idea. You should do it in a separate class, rather than mixing the logic with the display logic.
    Properties properties = new Properties();
    properties.load(UtilClass.class.getResourceAsStream("config.properties"));
    // Add a try - catch block around the load
    // for IOException...

  • How to read some records from a text file into java(not all records)

    hello,
    how to read text files into java. i need only few records from the text file not all records at a time.
    If any one knows plz reply me
    my id is [email protected]

    this snipet reads a text file line by line from line 1 to 3
    try {
                  FileReader fr = new FileReader(directory);
                  BufferedReader br = new BufferedReader(fr);
                  int counter = 0;
                  while ((dbconn = br.readLine()) != null) {
                      switch(counter){
                          case 0:
                            status = dbconn;
                          break;
                          case 1:
                            userName = dbconn;
                          break;
                          case 2:
                            apword = dbconn;
                          break;
                      counter++;
                  br.close();
        }catch(IOException e){
        }

  • How to read the data in a txt file on a web site?

    I want to extract the numbers located in txt files on a web site. It's a normal url. Not a ftp.
    Does anyone know how to do it?

    Hi Tom,
    What do you want to extract from the text file??
    I wanted to extract an IP address from a pearl script from my FTP server and this was the vi that I used .I dont know if you are trying to do the same?
    Here is the vi.It is in LV 7.1
    Hope its helps .
    Good luck.
    ohiofudu.
    Certified LabVIEW Architect
    Certified TestStand Developer
    Attachments:
    PublicIP-Adresse.vi ‏31 KB

  • How to use certain entries from a txt file as metadata?

    So during my plugin development I stumbled on a problem.
    I have created a txt file for each picture telling me who's in the photos. So the first column in the file shows all the names that appear in the photo.
    I want to add those names into LR for each photo. I thought using them as metadata would be a good idea. Then I could let the user enter a name of some person and create a smart collection having all photos with that person in them.
    But putting it into practice isn't that easy.
    So I started with the classic metadata definition:
    metadataFieldsForPhotos = {
      id = 'Person',
      title = 'Person'
      dataType = 'string',
      searchable = true,
      browsable = true,
    Now I don't know how to actually read only the column entries of the txt file and displaying all the names appearing in it. Another problem is that each photo has its own txt file in "nameofphoto.jpg.txt" So LR must know which txt file belongs to a photo.
    I know my question isn't very specific but it would be great if someone could help...

    Thank you for the reply. Reading the file how I wanted worked fine and I chose to use keywords, as you suggested.
    So now I tried to add the keywords to the pictures and I get:
    "LrCatalog:withWriteAccessDo: could not execute action 'keywordProvider'. It was blocked by another write access call, and no timeout parameters were provided."
    There's my function so far:
    function Finder.findPerson(smartCollectionName)
         local catalog = LrApplication.activeCatalog()
         local photos = catalog:getMultipleSelectedOrAllPhotos()
           LrTasks.startAsyncTask( function()
                for i=1,#photos do
                     local photo = photos[i]
                     local photopath = photo:getRawMetadata("path")
                     local photoname = photo:getFormattedMetadata("fileName")
                     local folderpath = string.sub(photopath, 1, string.len(photopath) - string.len(photoname))
                     local metadataPath = folderpath .. "\.metaface\\" .. photoname .. ".txt"
                     local text = LrFileUtils.readFile(metadataPath)
                     local metadataValues = stringSplit(text)
                     for i = 0, #metadataValues do
                          catalog:withWriteAccessDo( "keywordProvider", function()
                               local keywords = catalog:createKeyword(metadataValues[i])
                               photos:addKeyword(keywords)
                          end)
                     end
               end
          end)
    end
    So what am I doing wrong?

  • How to read my information from a html file?

    Hi
    I saved an html file from a website.
    How can I read my information (For example the first URL) from the html file?
    following code reads line by line:
    using (StreamReader reader = new StreamReader(Application.StartupPath + @"\x.htm"))
    String line = String.Empty;
    while ((line = reader.ReadLine()) != null)
    MessageBox.Show(line);

    How about this...
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Diagnostics;
    namespace ReadFromHtml
    class Program
    static void Main(string[] args)
    using (StreamReader reader = new StreamReader(Environment.CurrentDirectory + @"..\..\..\page1.html"))
    String line = String.Empty;
    while ((line = reader.ReadLine()) != null)
    if (line.Trim().StartsWith("<a"))
    Console.WriteLine(line.Trim());
    break;
    Console.ReadLine();
    <!DOCTYPE html>
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta charset="utf-8" />
    <title>mobile craigslist</title>
    </head>
    <body>
    <h1>PAGE1.HTML</h1>
    <hr />
    <a href="http://mobile.craigslist.com">mobile craigslist</a>
    <hr />
    </body>
    </html>
    UML, then code

  • How to read the data from an excel file into MYSQL by java language

    Hi all,
    I have some data in excel spread sheet and I want to put the data into MYSQL data base. I created the tables in MYSQL> How can I write a program in JAVA that puts the value from excel sheet to mysql??
    I would appreciate your help
    regards

    By typing code at the keyboard... but presumably you meant to ask what code you should type.
    To get data out of Excel there are a few alternatives. The Google keywords I would use to find them are "java excel". I use Apache POI but there are other possibilities, I believe. As for getting the data into MySQL once you have extracted it from Excel, you would use JDBC. But you already knew that, didn't you? You did find the JDBC forum.
    In general it's better to ask a specific question on a forum. If you don't have a clue (which is the way we all start out) then just telling people that isn't going to be helpful. The best you're going to get is links to tutorials, which you could perfectly well have found for yourself by simple web searches.

Maybe you are looking for

  • ABAP Web Dynpro Application changes in Administation mode

    Hi, I Made changes to a webdynpro application using Administrator mode in se80 ie Web Dynpro Application->Test->Test in Administation mode. I made one element 'invisible' and ticked 'Final' check box. This element disappeared from my application. Now

  • My Safari crashes every time I do three fingers left-swipe

    I am a new Lion user. I have just upgraded my machine from Snow Leopard to Lion yesterday. My Safari crashes whenever I use three fingers left-wipe to make it go back to the previous page. These are my settings image on trackpad.... Is there anyone h

  • Editing for air but no broadcast monitor

    Hello. I hope you can help! I edited a :30 from footage off a Panasonic P2 camera (data files) that I treated like DVC50 NTSC 720x480 anamorphic. I do not have a broadcast monitor. The producer has one though, in another state. My question is, how to

  • Problem in Retreiving the Salesorder

    Hi All    I am trying to retrieve the salesorder number by passing the purchase order number.  But the requirement is, I should not use any SQL query for this retrieval.  In stead, I have to use some function module. Could anyone please suggest me an

  • Autoplay/auto start Bridge galleries on web page

    After setting up a Bridge gallery on a web page, how do you make the thing autoplay or auto start upon opening the web page?  I can't find a setting in Bridge when setting up the gallery, and I can't seem to find my answer anywhere with an internet s