اذهب إلى المحتوى
  • 0

جافا، مثال ع Ascii تعاملها مع الملف

Feras Awwad

السؤال

Recommended Posts

  • 1

أهلا بك،

هنا مثال لطباعة قيم Ascii  في ملف

import java.io.*;
import java.nio.charset.*;

public class Test {

    private static Charset UTF8 = Charset.forName("UTF-8");

    public static void main(String args[]) throws IOException {
        writeFile("./test.txt");
        readFile("./test.txt");
    }

    public static void writeFile(String path) throws IOException {
        Writer writer = new OutputStreamWriter(new FileOutputStream(path), UTF8);
        try {
            writer.write((char) 147);
        } finally {
            writer.close();
        }
    }

    public static void readFile(String path) throws IOException {
        Reader reader = new InputStreamReader(new FileInputStream(path), UTF8);
        try {
            int c = reader.read();
            System.out.println(c);
        } finally {
            reader.close();
        }
    }
}

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...