Results 1 to 4 of 4

Thread: i need help in file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Unhappy 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

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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") ;
        }
      }
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: i need help in file

    I just have one personal question!
    Why does all your posts have a sad or angry smiley?
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: i need help in file

    because i have certain time to deliver it to my dr thank you for your reply

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width