hi..help me please
in my project the user input two string &picture i want to write them to textFile but if user add again i want mix its input with other input then in read textFile just read determine three input ..this my code
public void actionPerformed(ActionEvent e) {
ImageIcon icon=new ImageIcon();
String s1=textField1.getText();
String s2=textField2.getText();
String image =(icon.getImage()).toString();
String k="*";
String text=s1+s2+image+k;
String fileName = "c:/MyVocabulary.text";
String[]a=text.split(k);
if (((JButton) e.getSource()).getName().equals("Close")) {
prj.setVisible(false);
}
if (((JButton) e.getSource()).getName().equals("Browse")) {
JFileChooser fc = new JFileChooser(); // create object of file
// Browser
File file; // create file variable
fc.setDialogTitle("Open File"); // set Title
int result = fc.showOpenDialog(prj); // make it visible
if (result == JFileChooser.APPROVE_OPTION) { // if click ok
file = fc.getSelectedFile();// get the selected file
textArea1.setImage(icon.getImage()); // update textField3
textField3.setText(file.getPath());
}
}
if (((JButton) e.getSource()).getName().equals("Add")) {
File file1=new File(fileName);
FileWriter fw=new FileWriter(file1);
BufferedWriter bfw = new BufferedWriter(fw);
bfw.write(text);
bfw.newLine();
bfw.close();
}
else if (((JButton) e.getSource()).getName().equals("Search")) {
File file1=new File(fileName);
FileReader fr=new FileReader(file1);
BufferedReader bfr =new BufferedReader(fr);
for (int i=0;i<a.length;i++){
if(a[i].equals(s1)){
String m="";
while((m=bfr.readLine())!=null){
m=m+"\n";
}
System.out.println(m);
}
bfr.close();
}
}
}
}
read and write to textFilebegginer java May 26, 2011 at 2:32 PM
hi..help me please in my project the user input two string &picture i want to write them to textFile but if user add again i want mix its input with other input then in read textFile just read determine three input ..this my code public void actionPerformed(ActionEvent e) { ImageIcon icon=new ImageIcon(); String s1=textField1.getText(); String s2=textField2.getText(); String image =(icon.getImage()).toString(); String k="*"; String text=s1+s2+image+k; String fileName = "c:/MyVocabulary.text"; String[]a=text.split(k); if (((JButton) e.getSource()).getName().equals("Close")) { prj.setVisible(false); } if (((JButton) e.getSource()).getName().equals("Browse")) { JFileChooser fc = new JFileChooser(); // create object of file // Browser File file; // create file variable fc.setDialogTitle("Open File"); // set Title int result = fc.showOpenDialog(prj); // make it visible if (result == JFileChooser.APPROVE_OPTION) { // if click ok file = fc.getSelectedFile();// get the selected file textArea1.setImage(icon.getImage()); // update textField3 textField3.setText(file.getPath()); } } if (((JButton) e.getSource()).getName().equals("Add")) { File file1=new File(fileName); FileWriter fw=new FileWriter(file1); BufferedWriter bfw = new BufferedWriter(fw); bfw.write(text); bfw.newLine(); bfw.close(); } else if (((JButton) e.getSource()).getName().equals("Search")) { File file1=new File(fileName); FileReader fr=new FileReader(file1); BufferedReader bfr =new BufferedReader(fr); for (int i=0;i<a.length;i++){ if(a[i].equals(s1)){ String m=""; while((m=bfr.readLine())!=null){ m=m+"\n"; } System.out.println(m); } bfr.close(); } } } }
java basic to high level a tutorial notes.balachandher August 29, 2012 at 9:49 PM
i need a java programming simple tutorial notes.....
Post your Comment