How to read and write a file in unicode?

Hello!
I have a problem with reading and writing files which are saved in unicode. with my current code I get strange boxes in my text
Do you need a special Reader/Writer for this?
Please, help me if you have any ideas.
cheers
import java.io.*;
import java.util.*;
public class StreamConverter {
   static void writeOutput(String str) {
       try {
           FileOutputStream fos = new FileOutputStream("test_uni.txt");
           Writer out = new OutputStreamWriter(fos, "UTF8");
           out.write(str);
           out.close();
       } catch (IOException e) {
           e.printStackTrace();
   static String readInput() {
      StringBuffer buffer = new StringBuffer();
      try {
          FileInputStream fis = new FileInputStream("file_uni.txt");
          InputStreamReader isr = new InputStreamReader(fis, "UTF8");
          Reader in = new BufferedReader(isr);
          int ch;
          while ((ch = in.read()) > -1) {
             buffer.append((char)ch);
          in.close();
          return buffer.toString();
      } catch (IOException e) {
          e.printStackTrace();
          return null;
   public static void main(String[] args) {
        String inputString = readInput();
        writeOutput(inputString);     
}

Are you saying there's only the three boxes at the beginning, and the rest of the text is okay? That sounds like a Byte Order Mark (BOM). The BOM is optional for UTF-8, but Java's I/O classes act like it's forbidden. They should check for it when reading so they can skip over it, but (for now, at least) we have to do that ourselves.
All you have to do is read the first three bytes from the InputStream and compare them to the BOM. If they match, you start reading the text from that position; otherwise you reset the InputStream and start reading from the beginning.
http://en.wikipedia.org/wiki/Byte_Order_Mark

Similar Messages

  • How to read and write to file on server

    can any body tell how to read or write to a file on server, like where do i keep the file and what does the path look like......on server
    stand alone i am reading and writing into file but when it comes to server i am confused how it works...i mean the path
    thank you

    The Path needs to be absolute:
    For example in Unix it would look like:
    /usr/paz/Test.txtIn Windows it would look like:
    C:/Paz/Test.txtHope this helps.
    Thanks and regards,
    Pazhanikanthan. P

  • How to read and write(a file .txt) from a URLConnection

    I try to read and write on one URLConnection. Is it possible ? How can i make it ?
    The reading part of my application work's but not the writting part
    That's a part of rhe code that i use to write :
    String Line = "Hi";
    MyUrl = new URL(this.getCodeBase(), FichierEvenement) ;
    Con = MyUrl.openConnection() ;
    Con.setDoOutput(true);
    Con.setDoInput(true);
    Con.setUseCaches(false);
    Dos = new DataOutputStream(new BufferedOutputStream(Con.getOutputStream( )));
    Dos.writeUTF(Line);
    Please help me :)

    What are you doing with the bytes written to the OutputStream? This info would help, but i do have a suggestion. I ran into this problem when trying to write strings using writeUTF. The output was all screwed up. So, maybe change your string to a character array. That way Unicode is displayed properly. This in conjunction with writing to an .html file instead of to the connection itself might work.

  • How to read and write Xml file at client side using JavaScript !

    Hello,
    i am new to javascript.
    I have requirement to read and update XML file at client side.
    Will you please guide what could be the best way to read and update XMl file using javascript.
    Thanks,
    Zuned

    This is a Java forum,not a Javascript forum. Maybe you should ask here [http://www.webdeveloper.com/forum/forumdisplay.php?forumid=3&s|http://www.webdeveloper.com/forum/forumdisplay.php?forumid=3&s].

  • How to read and write PDF files

    I need to read pdf file and get information about its pagenumbers and format and permission allowed ...........
    then i want to ghange some of this attribute ....................
    how can do this ....................and what's API i have to use.......................

    http://www.pdfbox.org/
    regards

  • How to read and write Binary files from Forms 6i C/S ?

    Hi There,
    I have a situation, where user wants to store attachements to a record (Could be any type of file, TXT, TIFF, or Word Doc etc.) and wanted to retreive later if they wanted to edit/read.
    We are using forms 6i and Oracle 9i in client/server environment setup. Does anybody know how to solve this requirment. I'm ale to load image files with read_image_file, but it could be text some times and it could be some thing elses like word doc or excel.
    Also i have to give user an option to view existing file attachments. I'm Planing to use BLOB in database table to store files.
    Any help in this regards is appreciated

    Thanks,
    Venkat

  • How to read and write a string into a txt.file

    Hi, I am now using BEA Workshop for Weblogic Platform version10. I am using J2EE is my programming language. The problem I encounter is as the above title; how to read and write a string into a txt.file with a specific root directory? Do you have any sample codes to reference?
    I hope someone can answer my question as soon as possible
    Thank you very much.

    Accessing the file system directly from a web app is a bad idea for several reasons. See http://weblogs.java.net/blog/simongbrown/archive/2003/10/file_access_in.html for a great discussion of the topic.
    On Weblogic there seems to be two ways to access files. First, use a File T3 connector from the console. Second, use java.net.URL with the file: protocol. The T3File object has been deprecated and suggests:
    Deprecated in WebLogic Server 6.1. Use java.net.URL.openConnection() instead.
    Edited by: m0smith on Mar 12, 2008 5:18 PM

  • How to read and write a data from extrenal file

    Hi..
    How to read and write a data from extrenal file using Pl/sql?
    Is it possible from Dyanamic Sql or any other way?
    Reagards
    Raju

    utl_file
    Re: How to Create text(dat) file.
    Message was edited by:
    jeneesh

  • How do I migrate files created in a Windows OS to a new external drive that is formatted as a MAC drive. I want to read and write these files back to the new drive.

    How do I migrate files from an external hard drive created in a Windows OS to a new MAC external drive? I want to read and write these files to the new drive.

    LKrzesowski wrote:
    How do I migrate files from an external hard drive created in a Windows OS to a new MAC external drive? I want to read and write these files to the new drive.
    If all you're trying to do is move the files from the Windows external to the Mac external, you can simply connect them both to the Mac and drag the files from the Windows drive to the Mac drive. If you want to move the files back and forth between them, you'll need to establish the format of the Windows external. Macs can read and write to FAT32 and exFAT (which can handle files larger than 4GB) formatted drives but can only read NTFS formatted drives without additional software. With the Windows drive connected, you can check its format with Disk Utility.

  • How to read and write on ntfs partitions??

    Hello everyone, thanks for viewing my post.  I want to know how to read and write on ntfs partitions under sata hd on my arch64 system.  I'm using kde as my de and dolphin does sees it but can't access it anyway.  I didn't had problem so far on mounting usb drives it just automounts maybe because it is a fat partition not a ntfs?  Please I need your help...Thanks in advance:)

    You will most likely need to rework your fstab.  The one from my desktop is shown below. If you want regular users to be able to access the partition, then you will need to change the gid option as I have done. Although you could create a group just for people you want to have access.
    You will need to know the device that your windows partition is held on of course. In my case it is my first hard disk, first partition, hence /dev/sda1.
    # /etc/fstab: static file system information
    # <file system> <dir> <type> <options> <dump> <pass>
    none /dev/pts devpts defaults 0 0
    none /dev/shm tmpfs defaults 0 0
    /dev/cdrom /media/cdrom auto ro,user,noauto,unhide 0 0
    /dev/dvd /media/dvd auto ro,user,noauto,unhide 0 0
    /dev/mapper/nvidia_fbgfhehd1 /boot ext2 defaults 0 1
    /dev/mapper/nvidia_fbgfhehd2 / reiserfs defaults 0 1
    /dev/mapper/nvidia_fbgfhehd3 /var reiserfs defaults 0 1
    /dev/mapper/nvidia_fbgfhehd5 /opt reiserfs defaults 0 1
    /dev/mapper/nvidia_fbgfhehd6 swap swap defaults 0 0
    /dev/mapper/nvidia_fbgfhehd7 /home reiserfs defaults 0 1
    /dev/sdd1 /mnt/andromeda vfat defaults 0 0
    /dev/sda1 /mnt/windows ntfs-3g defaults,user,gid=users 0 0
    My XP partition is set to mount automatically, as I regularly interchange documents between the OS's.
    Hope that helps.

  • How to read and write data in to a specified range of cells(it include multiple row & columns) in excel

    How to read and write data in to a specified range of cells(it include multiple row & columns) in excel

    CVI Comes with a sample project that explains how to read/write to a Excel file: choose "Explore examples..." in CVI welcome page and navigate to <cviSampleDir>\activex\excel folder where you can load excel2000dem.prj.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • File Read and Write using File Adapter in Bpel

    In Bpel Process i am using File Adapter ( Schema is Opaque) for read and write the file contents. i am able do successful deployment and read, write function in first time deployment, after that again i tired to run the application, its not going to write the content of file, its only writing the file with out data's or content in that file.
    Please help me...
    Saravanan

    Hi Eric
    In my domain.log file having the following details. In this file im unable to find out what the exact problem. Please look at this and help me.
    <2008-01-22 18:25:42,024> <INFO> <default.collaxa.cube.compiler> validating "C:\product\10.1.3.1\OracleAS_1\bpel\domains\default\tmp\.bpel_BPELProcess2_1.1_298e83988d77b6640c33dfeec11ed31b.tmp\BPELProcess2.bpel" ...
    <2008-01-22 18:25:49,850> <INFO> <default.collaxa.cube.engine.deployment> <CubeProcessFactory::generateProcessClass>
    Process "BPELProcess2" (revision "1.1") successfully compiled.
    <2008-01-22 18:25:49,914> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> Loading JCAActivationAgent for {portType=Read_ptt}
    <2008-01-22 18:25:49,914> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> JCAActivationAgent::load - Locating Adapter Framework instance: OraBPEL
    <2008-01-22 18:25:49,930> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> JCAActivationAgent::load - Done loading JCAActivationAgent for processId='bpel://localhost/default/BPELProcess2~1.1/
    <2008-01-22 18:25:49,930> <INFO> <default.collaxa.cube.engine.deployment> Process "BPELProcess2" (revision "1.1") successfully loaded.
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> JCAActivationAgent::uninit Shutting down the JCA activation agent, processId='bpel://localhost/default/BPELProcess2~1.0/', activation properties={portType=Read_ptt}
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> Adapter Framework instance: OraBPEL - performing endpointDeactivation for portType=Read_ptt, operation=Read
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.ws> <File Adapter::Outbound> Endpoint De-activation called in adapter for endpoint : D:\MAXIMUS_Project_Softwares\jdevstudiobase10132\jdev\mywork\MyLabs\BPELProcess2\in
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> JCAActivationAgent::init - Initializing the JCA activation agent, processId='bpel://localhost/default/BPELProcess2~1.1/
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> JCAActivationAgent::initiateInboundJcaEndpoint - Creating and initializing inbound JCA endpoint for:
    process='bpel://localhost/default/BPELProcess2~1.1/'
    domain='default'
    WSDL location='rd.wsdl'
    portType='Read_ptt'
    operation='Read'
    activation properties={portType=Read_ptt}
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> Adapter Framework instance: OraBPEL - endpointActivation for portType=Read_ptt, operation=Read
    <2008-01-22 18:26:02,730> <INFO> <default.collaxa.cube.activation> <File Adapter::Inbound> Endpoint Activation called in File Adapter for endpoint: D:\MAXIMUS_Project_Softwares\jdevstudiobase10132\jdev\mywork\MyLabs\BPELProcess2\in
    <2008-01-22 18:26:02,730> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> Adapter Framework instance: OraBPEL - successfully completed endpointActivation for portType=Read_ptt, operation=Read
    <2008-01-22 18:26:02,890> <WARN> <default.collaxa.cube.activation> <File Adapter::Inbound> PollWork::run exiting, Worker thread will die
    <2008-01-22 18:26:04,171> <INFO> <default.collaxa.cube.ws> <File Adapter::Outbound> Managed Connection Created
    <2008-01-22 18:26:04,171> <INFO> <default.collaxa.cube.ws> <File Adapter::Outbound> Connection Created
    <2008-01-22 18:26:04,171> <INFO> <default.collaxa.cube.ws> <File Adapter::Outbound> FileInteraction Created

  • How to Read and Write .XML datas   (HELP Plz...)

    hai everybody
    how to read and write xml datas... plz give clean and simple example..
    bcoz me want to produce such type of module...
    if any one help me .. thats the only way me laid in software ladder
    plz....
    thank u in advance

    thank u for giving idiot..
    but before posting i search in google also..
    but i cant get what me expect..
    thus i posted...
    then who is ................?
    sorry javacoder01
    // plz help me
    Message was edited by:
    drvijayy2k2

  • How to read and create TDM Files in a Java Applicatio​n?

    Hi,
    I want to read and write TDM-Files in a Java-Application.
    I found the TDMHeaderWriter for Java, that can write TDM-Files, but the reading part is still missing.
    Perhaps anyone knows an equivalent in Java to the TDM C DLL and the TDM C Header DLL?
    Thanks Verena

    Cool 
    Can you please give me feedback on this project if you have finished it?
    Matthias
    Matthias Alleweldt
    Project Engineer / Projektingenieur
    Twigeater?  

  • I'm trying to share folder between users on a single mac.  I put the folder in "shared," set permissions so other user can read and write, enabled file sharing, but can't find the folder on the second user's account.  Any help?

    I'm trying to share a folder between users on a single mac.  I want both users to be able to read and write so the folder stays current on both accounts.  I put the folder in "shared," set permissions on folder so other user can read and write, enabled file sharing, but can't find the folder on the second user's account.  Any help?

    Did you log out of one account and into the other or just used Fast user switching?
    Is the permissions set to anyone?
    When you move data to teh Shared folder is it copied or just moved?
    If copied then it's not a folder both can access, just a way station like a USB thumb drive that things are coped too and off of likely.
    You can run this #5 on each user account to reset the user permissions once they are taken back out of the Shared folder
    Step by Step to fix your Mac

Maybe you are looking for

  • List View Report with pipelined function in Mobile application and ORA-01007: variable not in select list

    Hi! I have a problem with List View Report in mobile application (theme 50 in apex) after updating to apex 4.2.2. I created Report -> List View. I used select from pipelined function in Region Source. Then when page is running and submited three time

  • Why can't Apple just turn up the **** fans?

    We all agree that the macbook pro is an incredibly toasty little computer. Not a laptop - a notebook.... When I run the CPU at full throttle my MBP gets cooler because the fans start. So, even though the CPU is running at 73C, the upper surface tempe

  • Dynamic SQL Stored Procedure call in Pro*C Application

    Hello All Could you help with a sample Pro*C program (or snippet) which has a dynamic call to a stored procedure? The procedure to be called is determined at run time and so also the number of parameters to it. Is this even possible using Pro*C? Than

  • How to Create Crystal System in the System Configuration

    Hi I am trying to integrate Crystal system in the Enterprise Portal. When i am trying to create i am not able to see the Crystal Report System in the System list. Please let me know how to configure (Intigrate) Crystal System in the portal and how to

  • Deleting a rebate with Accruals

    Hello Gurus, I have a scenario where i need to delete a rebate which has accruals. If i try to delete the rebate it says "Order type has not been defined in the sales Area". Is there any way to delete/settle this rebate without maintaining this custo