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

السلام .. كيف أسوي تعديل للبيانات (update) +شرح

بدأه عبودي البلوي في 8 يناير 2011 · 1 رد · 544 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

ممكن التعديل على ال case 5 وإذا ممكن شرح معنى كل كود

import java.io.*;
import java.util.*;

public class test {

public static void main(String[] args)throws Exception {

Scanner input = new Scanner(System.in);


//...........................................................................
   	boolean quit = false;
 do { 
            int menu = 0;
          System.out.println("******************************");
     	System.out.println("Telephone Directory");
     	System.out.println();
     	System.out.println("1. Accept Data");
     	System.out.println("2. Search");
     	System.out.println("3. List of all persons");
     	System.out.println("4. Exit");
     	System.out.println("5. update");


     	System.out.print("Please enter your choice: ");
     	menu = input.nextInt();
     	System.out.println();
//...........................................................................
 switch (menu) {
 case 1:
          System.out.print("Enter Name: ");
          String name = input.next();
          System.out.print("Enter Address: ");
          String address = input.next();
          System.out.print("Enter Phone No: ");
          int no = input.nextInt();
          FileWriter fw = new FileWriter(new File("directory.txt"), true);
          BufferedWriter out = new BufferedWriter(fw);
          out.write(name + " " + address + " " + no);
          out.write(name + " " + address + " " + no);
          out.newLine();
          out.close();
     	System.out.println( name + " " + address + " " + no);

    break;
//...........................................................................
   	case 2://Search
            System.out.print("Enter name to search information: ");
     	String n = input.next();
     	File f = new File("directory.txt");
 	try {
          BufferedReader freader = new BufferedReader(new FileReader(f));
          String s;
          while ((s = freader.readLine()) != null) {
          String[] st = s.split(" ");
          String nm = st[0];
          String add = st[1];
          String phoneNo = st[2];
          if (n.equals(nm)) {
          System.out.println("***********Information**************");
          System.out.println("Address : " + add);
          System.out.println("PhoneNo : " + phoneNo);
     	}
     	}
     	freader.close();
     	} 
    catch (Exception e) {
                            }
        break;
//...........................................................................   
   case 3://list
      FileInputStream fis = new FileInputStream(new File("directory.txt"));

 	try {
 		DataInputStream dis = new DataInputStream(fis);
 	BufferedReader reader = new BufferedReader( new InputStreamReader(dis));
 	String st;
   ArrayList al = new ArrayList();
   while ((st = reader.readLine()) != null) {
      al.add(st);
 	}
 	Iterator itr;
 	for (itr = al.iterator(); itr.hasNext()[img=/public/style_emoticons/default/wink_smile.gif] {
 	String str = itr.next().toString();
 	String[] splitSt = str.split(" ");
 	String na = "", ada = "", ph = "";
 	for (int i = 0; i < splitSt.length; i++) {
 	na = splitSt[0];
 	ada = splitSt[1];
 	ph = splitSt[2];
                                   	}
    System.out.println(na + " " + ada + " " + ph);
      }

     	reader.close();
     	} 
    catch (Exception e) {
                            }

   	break;
//...........................................................................
   case 4 ://exit
          quit = true;
   break;
//...........................................................................
  case 5 ://update 
       System.out.print("Enter name to update information: ");
     	String a = input.next();
     	File fi = new File("directory.txt");
 	try {        //  }
          }
     	freader1.close();
     	} 
    catch (Exception e) {
                            }
  break;
   default:
        System.out.println("Invalid Entry!");
        }
        } while (!quit);
}
}

test.java

تم تعديل هذه المشاركة بواسطة علاء الصالحي في 9 يناير 2011 في 04:39 — السبب: إضافة وسم code

#2

لا يمكن أن تجد من سيساعدك

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

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

عدد الزوار حالياً

المتواجدون خلال آخر ساعة · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…