الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كود للتعامل مع ملف text

مغلق
بدأه حمدي البنا في 14 يونيو 2003 · 5 رد · 822 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

هذا الكود للقراءة من ملف text وطباعته

وطباعه عدد الحروف(bytes)

#2
import java.io.*;
public class ReadFile
{
  public static void main(String[] args) throws IOException
  {
    FileInputStream in=new FileInputStream("Memo.txt");
    // the Memo text file must be found in the main directory that contain class,src
    byte buf[]=new byte[128];
    int bytecnt=0;
    String line;

    in.read(buf,0,128);//read from text and put in buf

    String s=new String(buf,0);
    System.out.println(s);
   //in.close();
   in=new FileInputStream("Memo.txt");//open connection again to count it
    while(in.read() != -1)
    {
      bytecnt++;
    }
    System.out.println("The count of text is " + bytecnt + " in bytes");

  }
}
#3

شكرا اخي نحن بحاجة الى مثل هذه الاكواد البسيطة و المفيدة و بشكل كبير لكي ننقلها الى الآرشيف فهو شبه فارغ

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#4

السلام عليكم

اين هذا الآرشيف اخي لا اعلم اين هو ارجوا ان تخبرني مكانه للتعامل مع مباشرة (f)

#5

لمعرفة حجم ملف معين يمكن استخدام

import java.io.*;
public class MyReadFile
{
  public static void main(String[] args) throws IOException
  {
    File F=new File("C:Dokumente und EinstellungenkhaledDesktopdata.txt");
    System.out.println(F.length());
  }
}
اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#6

جزاك الله خيرا

هذا الموضوع مغلق.

مواضيع مشابهة