20220223 º¹½À
< ¹Ì´ÏÇÁ·ÎÁ§Æ® 3ÀÏÂ÷ >
package add.addView;
import java.util.*;
import java.io.*;
public class AddView {
// p249(method)
static void addRead() { // p904 (ÆÄÀÏÀÔÃâ·Â) p414 (¿¹¿Üó¸®)(»ó¼Ó)
String fname="address.txt";
String line="";
//p915 (ÆÄÀÏÀÌ ¾øÀ¸¸é ¸¸µé¾î¶ó)
File f = new File(fname);
if (!f.exists()) {
try {
FileWriter fw = new FileWriter(fname);
BufferedWriter bw = new BufferedWriter(fw);
bw.close();
} catch (IOException e) {
}
}
try {
FileReader fr=new FileReader(fname);
BufferedReader br=new BufferedReader(fr);
for (int i = 0; ( line= br.readLine() ) != null; i++) {
System.out.println(line);
}
br.close(); // ¿·ÁÀÖ´Â FileÀ» ²À ´Ù½Ã ´Ý¾ÆÁÖ±â
}catch(IOException e){
System.out.println("¿¡·¯¹ß»ý");
}
}
static void addCreate() {
Scanner sc=new Scanner(System.in);
String name;
String phone;
String email;
String address;
String add_list="";
String fname="address.txt"; // FileWriter (µ¤À¸¾º¿ì±âX Ãß°¡ÇϱâO)
String line="";
try {
FileWriter fw = new FileWriter(fname, true); // True·Î Ãß°¡ÇØÁÖ±â
BufferedWriter bw = new BufferedWriter(fw);
// Scanner·Î ÀԷ¹޾Ƽ add_list ä¿ì±â!!!
System.out.print("Ãß°¡ÇÒ À̸§À» ÀÔ·ÂÇØÁÖ¼¼¿ä: ");
name = sc.nextLine();
System.out.println(name);
System.out.print("Ãß°¡ÇÒ ÀüȹøÈ£¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä: ");
phone = sc.nextLine();
System.out.println(phone);
System.out.print("Ãß°¡ÇÒ À̸ÞÀÏÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä: ");
email = sc.nextLine();
System.out.println(email);
System.out.print("Ãß°¡ÇÒ ÁÖ¼Ò¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä: ");
address = sc.nextLine();
System.out.println(address);
add_list = name +","+ phone +","+ email +","+ address;
System.out.println("Ãß°¡ÇÑ ³»¿ë: "+add_list);
bw.write(add_list);
bw.newLine(); // µ¥ÀÌÅÍ ÀÔ·Â ÈÄ ¹ØÀ¸·Î °³Çà
bw.close();
} catch (IOException e) {
}
}
static void addUpdate() {
System.out.println("update!!");
}
static void addDelete() {
System.out.println("delete!!");
}
static void addSearch() {
System.out.println("search!!");
}
static void addBackup() {
/*
* ¼¹ö°¡ Áغñ µÇ¾îÀÖ´ÂÁö È®ÀÎ
* FTP 21
* ¾ÆÀ̵ð, ºñ¹Ð¹øÈ£
*/
}
static void addMenu() {
//p36 (printf)
System.out.println("< ¹Ì´Ï ÇÁ·Î±×·¥ À̸§ >");
System.out.println("1. ÁÖ¼ÒÃâ·Â");
System.out.println("2. ÁÖ¼Òµî·Ï");
System.out.println("3. ÁÖ¼Ò»èÁ¦");
System.out.println("4. ÁÖ¼Ò¼öÁ¤");
System.out.println("5. ÁÖ¼Ò°Ë»ö");
System.out.println("6. Á¾·á");
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String select="";
while (select!="6") {
addMenu();
System.out.println("-¹øÈ£¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä.-");
select=sc.nextLine();
switch (select) {
case "1":
addRead();
break;
case "2":
addCreate();
break;
case "3":
addUpdate();
break;
case "4":
addDelete();
break;
case "5":
addSearch();
break;
case "6":
addBackup();
return;
default:
System.out.println("À߸øµÈ ¹øÈ£. ´Ù½Ã ÀÔ·ÂÇϽÿÀ.");
}
}
/*
addMenu();
addRead(); 1
addCreate(); 2
addUpdate(); 3
addDelete(); 4
addSearch(); 5
*/
}
}
< ¸Å´º¾ó >
< ÆÐÅ°Áö >
Model ( µ¥ÀÌÅͺ£À̽º X, ÆÄÀÏ )
View ( UI, html ȸ鱸¼º )
Controller ( java ±â´É )
add_model
add_view
add_controller
< ÇÔ¼ö >
static void addRead() {
String fname="xxx.txt";
String line="";
File f = new File(fname);
if (!f.exists()) {
try {
FileWriter fw = new FileWriter(fname);
BufferedWriter bw = new BufferedWriter(fw);
bw.close();
} catch (IOException e) {
}
}
//-------------------------------------------
try {
FileReader fr=new FileReader(fname);
BufferedReader br=new BufferedReader(fr);
for (int i = 0; ( line= br.readLine() ) != null; i++) {
System.out.println(line);
}
br.close(); // ¿·ÁÀÖ´Â FileÀ» ²À ´Ù½Ã ´Ý¾ÆÁÖ±â
}catch(IOException e){
System.out.println("¿¡·¯¹ß»ý");
}
}
static void addCreate() {
Scanner sc = new Scanner(System.in);
String fname="xxx.txt";
String xx;
String xx;
String xx;
String xx;
String add_list="xx+xx+xx+xx";
try{
FileWriter fw = new FileWriter(fname, true);
BufferedWriter bw = new BufferedWriter(fw);
System.out.println("Ãß°¡ÇÒ xxÀ» ÀÔ·ÂÇϽÿÀ.");
name = sc.nextLine();
add_list = xx + xx ;
bw.write(add_list);
bw.newLine();
bw.close();
} catch (IOException e) {
System.out.println("¿¡·¯¹ß»ý(FileWriting-FAIL)");
}
}
static void addUpdate() {
}
static void addDelete() {
}
static void addSearch() {
}
static void addBackup() {
/*
* ¼¹ö°¡ Áغñ µÇ¾îÀÖ´ÂÁö È®ÀÎ
* FTP 21
* ¾ÆÀ̵ð, ºñ¹Ð¹øÈ£
*/
}
static void addMenu() {
System.out.println("1. ÁÖ¼ÒÃâ·Â");
System.out.println("2. ÁÖ¼ÒÃß°¡");
System.out.println("3. ÁÖ¼Ò¼öÁ¤");
System.out.println("4. ÁÖ¼Ò»èÁ¦");
System.out.println("5. ÁÖ¼Ò°Ë»ö");
System.out.println("6. Á¾·á");
}
-----------¸ÞÀÎÇÔ¼ö-----------
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String select="";
while (select!="x") {
addMenu();
System.out.println("-¹øÈ£¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä.-");
select=sc.nextLine();
switch (select) {
case "1":
addRead();
break;
case "x":
addBackup();
return;
default:
System.out.println("À߸øµÈ ¹øÈ£. ´Ù½Ã ÀÔ·ÂÇϽÿÀ.");
}
}