php2008. 11. 17. 13:49
* ANSI 텍스트 파일 
- 특별한 표식이 없습니다.

* 유니코드 (little endian)
파일 처음에 0xFF 0xFE 의 두바이트로 시작합니다.

* 유니코드 (big endian)
파일 처음에 0xFE 0xFF 의 두바이트로 시작합니다.

* UTF-8 
파일을 덤프 해본 결과 파일 처음에 0xEF 0xBB 0xBF 의 세바이트로 시작합니다.



한번 파일을 만든후 덤프 해보시기 바랍니다 
그럼 즐삽

window desktop search 4.0에서
해보았는데 한글이 검색이 안되길레 utf8문제 인지 알았더니 

윈도우에서 utf8을 제대로 인식을 못해서 그런듯 txt를 만드는 코딩을할때 이거를 잘 바야할듯
0xEF 0xBB 0xBF

쉽게도 UTF-8 지원은 안되는쪽이 맞는것 같습니다... 사용할 수도 있을뿐..
정상적인 UTF-8 문서 첫머리에는 BOM 문자(0xEF 0xBB 0xBF)가 있어야 하지만 세션등 헤더를 사용하는 php 프로그램에서 BOM 문자가 먼저 출력되어 headers already sent 에러가 납니다..
결국 열어보기 전에는 charset을 알수 없는 BOM을 제거한 텍스트만 저장해야 하게 되죠.. 다른 좋은 장점들을 깎아먹는 아쉬운 부분입니다.^^

 index.xml은 utf-8로 구성이 되어있습니다. 그런데 index.xml이 UTF-8이라는 것을 표시하기 위해서 제일 앞에 signature가 붙어있습니다. 0xef0xbb0xbf가 그것인데요, 그것이 붙어있으면 제대로 인식하지 못하는 컴퓨터가 있는 것 같네요


he Byte-Order Marker (BOM)

이것은 파일 앞에 붙어서 이 파일이 UTF-8 인 것을 알려준다.
그러면 editor들은 이걸 제외하고 알아서 읽어 드리게 된다.
save 할 때에도 Windows에서는 이걸 file앞에 집어 넣는다.
하지만 Mac OS X는 save할 때 이것을 없는 상태로 save 한다.
0xef 0xbb 0xbf 의 값이다.
 
UTF-8 에서만 쓰이 는 줄 알았는데,
Unicode 전부에서 쓰인다.
어떤 unicode를 써서 encoding 되었는지를 알려주며,
little endian 인지, big endian 인지 여부도 알려준다.
 
EncodingRepresentation
UTF-8EF BB BF
UTF-16 Big EndianFE FF
UTF-16 Little EndianFF FE
UTF-32 Big Endian00 00 FE FF
UTF-32 Little EndianFF FE 00 00
SCSU0E FE FF
UTF-72B 2F 76
and one of the following byte sequences: [ 38 | 39 | 2B | 2F | 38 2D ]
UTF-EBCDICDD 73 66 73
BOCU-1FB EE 28
 










C# code make txt file

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WordIndexSpliter
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string strFileName = ExecuteDialogProcess();
            
            string strBuffer = string.Empty;
            string strOutFileName = string.Empty;
            string strTempFileName = string.Empty;
            

            StreamReader streamReader = new StreamReader(strFileName);         
            

            while ((strBuffer = streamReader.ReadLine()) != null)
            {
                if (strBuffer.Length > 1)
                {
                    string[] pageNum = strBuffer.Split(new Char[] { ',' });

                    //7월23일 Format을이용해서 바꿈
                    strTempFileName = strFileName.Substring(0, strFileName.LastIndexOf(".")) + "_" + string.Format("{0:00000000}", int.Parse(pageNum[0])); 
                    StringBuilder stringBuilder = new StringBuilder( Path.GetFileName(strTempFileName));
                    //7월23일 파일이름을 123123_00001.txt형식에서 중간중간에 $를 넣는다.
                    char[] arrChr = Path.GetFileName(strTempFileName).ToCharArray();
                    StringBuilder sbResultText = new StringBuilder();
                    foreach (char str_chr in arrChr)
                    {
                        sbResultText.Append("$" + str_chr);                        
                    }
                    sbResultText.Append("$");
                    strOutFileName = Path.GetDirectoryName(strTempFileName) + "\\" + sbResultText.ToString() + ".txt";
                                        
                    FileStream fileOutStream = null;
                    if (!File.Exists(strOutFileName))
                    {
                        byte[] byByteOrderMark = { 0xEF, 0xBB, 0xBF };
                        fileOutStream = new FileStream(strOutFileName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                        fileOutStream.Write(byByteOrderMark, 0, byByteOrderMark.Length);
                        fileOutStream.Close();
                    }
                    fileOutStream = new FileStream(strOutFileName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
                    byte[] byOutBuffer = UTF8Encoding.UTF8.GetBytes(strBuffer + "\r\n");
                    fileOutStream.Write(byOutBuffer, 0, byOutBuffer.Length);
                    fileOutStream.Close();
                    
                }
            }
            streamReader.Close();            
        }

        private string ExecuteDialogProcess()
        {
            OpenFileDialog openDialog = new OpenFileDialog();
            openDialog.Filter = "Word Index File|*.idx|All File|*.*";

            openDialog.ShowDialog();
            
            return openDialog.FileName;
            //return openDialog.SafeFileName;
        }
    }
}

Posted by 동동(이재동)