[질문] file write에 관하여


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]

글쓴이 :candy 1998년 1월 21일 14:01:27

제가 하고자 하는 일은 특정 화일의 내용을 읽어서 textarea에 그 내용을 보여주고 edit작업을 한 후 저장 버튼을 누르면 그 내용이 저장되기를 원합니다. 읽는 데서는 문제가 없었는데 화일에 그 내용을 쓰는데 문제가 있습니다.
배운지 얼마되지 않아서 프로그램이 깔끔하지를 못합니다. 아시는 분은 저에게 도움을 좀.....
덧붙여 물어보면 여러개가 있는 InputStream을 각각 어디서 써야할 지 확실히 구분이 되지 않습니다.
좋은 강의를 기다리면서.....


<예제>


import java.awt.*;
import java.io.*;
import java.awt.event.*;
public class DisplayFile  {
	FileInputStream fi;
	FileOutputStream fo;
	File myFile;
	String FileName;
	TextArea ta;
	Frame f;
	Button bok;
	public static void main(String args[]) {
	
		DisplayFile Df = new DisplayFile(args[0]);
		
		Df.init();
		
	}
	
	public DisplayFile(String temp) {
		
		FileName = temp;
		f = new Frame();
	}
	public void init() {
		myFile = new File(FileName);
		byte b[] = new byte[(int) myFile.length()];
		try {
		fi = new FileInputStream(myFile);
		
		} catch (FileNotFoundException e) {
			System.out.println(" file not found");
		} 
		
		try {
		fi.read(b);
		} catch (IOException e1) {
			System.out.println("IO Error");
		}
		String s = new String(b);
		
		ta = new TextArea(s , 20 , 50);
                         
                bok = new Button("SAVE");
                bok.addActionListener(new ButtonHandler());
                f.add(ta , "Center");
                f.add(bok , "North");
		f.setSize(100,100);
                f.setVisible(true);
                f.addWindowListener (new WindowHandler());
                
	}
	private class WindowHandler extends WindowAdapter {
		public void windowClosing (WindowEvent e4) {
                       f.setVisible(false);
                       f.dispose();
                       System.exit(0);
		}
	}
	
        private class ButtonHandler implements ActionListener {
                 public void actionPerformed(ActionEvent e5) {
                       String imsi;
                         imsi = ta.getText();
                     
                        byte b1[] = new byte[(int) imsi.length()];
		try {
		fo = new FileOutputStream("ko.txt");
		
		} catch (FileNotFoundException e) {
			System.out.println(" file not found");
		} catch (IOException ee) {
                        System.out.println("IO ERROR");
                }
		
		try {
		fo.write(b1);
		} catch (IOException e1) {
			System.out.println("IO Error");
		}
                }
        }
}



다음 글들:



이어서 글올리기(답하기)

이름:
E-Mail:
제목:
내용:
관련 URL(선택):
URL 제목(선택):
관련 이미지 URL:


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]