.txt kayıt turunu UTF-8 nasıl yaparım

metinbeci (1) 6 yıl önce sordu

Merhaba basic ile yazdıgım bir programda c:\kasa dizinin altında hesap.txt dosyası varmı yokmu diye kontrol ettiriyorum eğer yoksa oluşturuyorum daha sonra içerisine yazdırmak istediklerimi yazdırıyorum fakat dosya kayıt türü türkce karakterden dolayı işimi görmüyor ANSI olarak kaydediyor.ben dosya kayıt türünün UTF-8 olmasını istiyorum yapamadım belki dosya olustukdan sonra formatını değiştirebilirim diye düşünüyorum.Nasıl bir yol izlemem gerekiyor.Kullandıgım kodlar asagıda.

 

    Dim kasa_fs As System.IO.FileStream = New System.IO.FileStream("C:\kasa\hesap.txt", IO.FileMode.Create)
    Dim kasa_wr As System.IO.StreamWriter = New System.IO.StreamWriter(kasa_fs)

    kasa_wr.Close()

   FileOpen(1, "C:\kasa\hesap.txt", OpenMode.Output)

   PrintLine(1, hesap_kod+ Space(30 - Len(hesap_kod)) + Mid(hesap_ad, 1, 25))

 

bu sekıllerde de denedım ama hata aldım

Dim kasa_wr As System.IO.StreamWriter = New System.IO.StreamWriter(kasa_fs, False, Encoding.UTF8)

Dim kasa_wr As System.IO.StreamWriter = New System.IO.StreamWriter(kasa_fs, True, System.Text.Encoding.Default)

hata mesajı :

error 15 Overload resolution failed because no accessible 'New' can be called with these arguments: 'Public Sub New(path As String, append As Boolean, encoding As System.Text.Encoding)': Value of type 'System.IO.FileStream' cannot be converted to 'String'. 'Public Sub New(stream As System.IO.Stream, encoding As System.Text.Encoding, bufferSize As Integer)': Value of type 'Boolean' cannot be converted to 'System.Text.Encoding'. 'Public Sub New(stream As System.IO.Stream, encoding As System.Text.Encoding, bufferSize As Integer)': Value of type 'System.Text.Encoding' cannot be converted to 'Integer'.

toprak34 6 yıl önce

@alattin

alattin 6 yıl önce

o iş bende @toprak34

toprak34 6 yıl önce

:) @alattin

Toplam 2 cevap


alattin (16999) 6 yıl önce cevapladı

StreamWriter'ı şu şekilde oluşturursan hata almayacaksın:

   Dim stWriter As New System.IO.StreamWriter(New IO.FileStream("C:\kasa\hesap.txt", IO.FileMode.Create), System.Text.Encoding.UTF8)
    

 

metinbeci (1) 6 yıl önce cevapladı

evet yazdığın şekilde yapınca hata vermiyor ama txt dosyasınıda UTF-8 olarak kayıt etmiyor ANSI yapıyor yani sorun çözülmedi.madem txt UTF-8 olarak kayıt edemiyoruz peki txt olustukdan sonra yapısını değiştirebilirmiyiz mesela 

c:\kasa\hesap1.xls dosyasını c:\kasa\hesap1.doc gibi tabi buradaki ornek uzantıyla ilgili benimki kayıt türü yani char set UTF-8 e sonradan donusturebilirmiyiz.

alattin 6 yıl önce

Ansi olduğunu nereden çıkardın? Yukarıdaki kod utf-8 oluşturur.