-
i need help in file
i creat Jcombo box that contain names of file
and i make the following step to put the user select to astring
String h=jb1.getSelectedItem().toString();
and according to string h which is the name of file i want this file to be write
file f=new file(h)
FileReader fr = null ;
BufferedReader br = null;
BufferedWriter bw= null;
try
{
fr = new FileReader(in);
br = new BufferedReader(fr);
while ((thisLine = br.readLine()) != null)
{
System.out.println(thisLine);
//out.close();
}
}
catch (Exception l)
{
System.out.print("error");
}
}
but when i run that it tell me that it can not find the file
i fell that because i pass string h not (Ex."in.txt) how i can solve that
note i can pass the name of file direct
help me please
-
Re: i need help in file
Here is the right code to make it work:
Code:
public static void main (String[] args){
JFileChooser jb1=new JFileChooser();
jb1.showOpenDialog(null);
String h = jb1.getSelectedFile().getPath();
File f = new File(h) ;
FileReader fr = null ;
BufferedReader br = null ;
BufferedWriter bw = null ;
String thisLine = "" ;
try {
fr = new FileReader(f) ;
br = new BufferedReader(fr) ;
while ((thisLine = br.readLine()) != null) {
System.out.println(thisLine) ;
//out.close();
}
}
catch (Exception l) {
System.out.print("error") ;
}
}
-
Re: i need help in file
I just have one personal question!
Why does all your posts have a sad or angry smiley?
:D http://www.vbforums.com/images/ieimages/2006/02/1.gif
-
Re: i need help in file
because i have certain time to deliver it to my dr thank you for your reply