Results 1 to 6 of 6

Thread: Browse a file in java

  1. #1
    Join Date
    Dec 2009
    Posts
    192

    Browse a file in java

    Hello,
    I want to browse a file and to replace some lines of words by others, is it possible in Java to parse a file line by line ? I know another solution that does not suit me at the moment c open another file where I copy it line by line the contents of the initial file (by not putting much on the lines changed from File out) but it cost me a lot. Can you help me to do otherwise? Any help on this topic on this will be highly appreciated.

  2. #2
    Join Date
    Nov 2009
    Posts
    330

    Re: Browse a file in java

    Hello,
    Just have a look at the below example, may be it will help you.
    Code:
    while ((line = bf.readLine()) != null) {
    System.out.System.out.println(line);
    / / do your coding here 
    }
    line is a String so you can do all the handling specific to that object (replacing the word by making the other party ) Just try it and then if you have any problem do post back.

  3. #3
    Join Date
    Nov 2009
    Posts
    583

    Re: Browse a file in java

    Hello,
    Topic multiple times. In short, if the old chain has the same size as the new channel, you can content yourself to work directly on the original file. Otherwise, you have no choice but to go through another file. This is not a limitation of Java, but applies to all programming languages. In what sense is it costing you a lot? If you describe your problem precisely, then it will be better for us to understand and interpret like wise.

  4. #4
    Join Date
    Dec 2009
    Posts
    192

    Re: Browse a file in java

    Hi,
    Thank you for the answer already. But this is not what I actually want. I'll explain better, I want to retrieve the current row
    that is line is a String
    The change (with a line.replaceAll (...)) for example and replace the current line from the file by the line that I just modified, in other words use a single file for make the read / modify rows.

  5. #5
    Join Date
    Dec 2009
    Posts
    211

    Re: Browse a file in java

    Hello,
    Even I have some similar problems with my code. The words change in the line being played are not bulky. This cost me to rewrite in another file. for the simple reason that staying in the same directory:
    1) I'll have to name the file created by another name,
    2) Finish the transfer, then transfer the old file that has been traveled.
    3) Then rename the one I just created with the name of the file I deleted.
    And c ca is expensive for me. If I can directly bump on a single file and save it to take into account changes in the lines I made this is super easy and fast at the same time.

  6. #6
    Join Date
    Dec 2009
    Posts
    192

    Re: Browse a file in java

    Hello,
    This is my code, please have a look at it, if i am wrong somewhere then guide me.
    Code:
    Public static void readReplace(String fileName, String oldPattern, String replPattern)
    	{
    			String ln;
    StringBuffer sb = new StringBuffer();
    			try {
    			FileInputStream fis = new FileInputStream(fileName);
    BufferedReader rd = new BufferedReader(new InputStreamReader(
    			fis));
    			while ((ln = rd.readLine()) != null)
    			{
    				ln = ln.toLowerCase();
    ln = ln.replaceAll(oldPattern.toLowerCase(), replPattern);
    sb.append(ln + "\ n");
    			}
    				rd.close();
    BufferedWriter ot = new BufferedWriter(new FileWriter(fileName));
    ot.write(sb.function toString() {
        [native code]
    }());
    ot.close();
     
    			} catch (Exception e) {
    			}
    			
    	}

Similar Threads

  1. Firefox 12 not giving option to browse for local file on Windows 7
    By Dinesh Chaudhri in forum Technology & Internet
    Replies: 2
    Last Post: 26-04-2012, 06:04 PM
  2. Browse without java on Acer Iconia A500 Tab
    By emMetTi in forum Portable Devices
    Replies: 6
    Last Post: 06-08-2011, 09:45 PM
  3. how to browse ftp file in eclipse
    By Ashton5 in forum Technology & Internet
    Replies: 3
    Last Post: 17-06-2009, 04:58 PM
  4. Cannot browse internet by URL but can browse with IP
    By Bertus in forum Technology & Internet
    Replies: 3
    Last Post: 06-03-2009, 08:51 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,893,358.78778 seconds with 16 queries