swing - Creating an Open Function in Java using JFIleChooser -
hi having issues completetly understanding feature of notepad. want user ot search .txt file desire in directory , able open it. remember notepad file must readeable , writable. created simple open stuck in fact keep getting red in br = new bufferedreader(new filereader(open));, on new filereader(open)); part. how can fix this? appreciated. public void actionperformed (actionevent event) {
if(event.getsource() == this.newfile){ this.textarea.settext(""); }else if(event.getsource() == this.openfile){ jfilechooser open = new jfilechooser(); int option = open.showopendialog(this); filereader fr; bufferedreader br; if(option == jfilechooser.approve_option){ try{ br = new bufferedreader(new filereader(open)); //while(){ //} }catch(exception ex){ system.out.println(""); } } } }
jfilechooser
not file
, can not used parameter filereader
, instead, need selected file
chooser...
file choosenone = open.getselectedfile(); br = new bufferedreader(new filereader(choosenone ));
there options available make life little easier, filters.
check out how use file choosers more details
Comments
Post a Comment