Results 1 to 2 of 2
  1. #1
    DMarsh12 is offline Member
    Join Date
    Mar 2011
    Posts
    43
    Rep Power
    0

    Default Simple Text File Editing in Java help

    I am trying to write a code that will multiply the values of my text file (1 2 3 4 5 6 7 8 9) by 3 so that the output when I open my txt file is 3 6 9 12 15, 18, 21, 24, 27. Right now I can display my text file in java but i don't know how to edit it.

    Any Help is greatly appreciated

    Java Code:
    /**
     * 
     */
    
    /**
     * @author DMarsh
     *
     */
    
    	 import java.io.*;
    
    	 public class Data2 {
    
    	     public static void main(String[] args) {
    	     	try {
    	     		FileInputStream fstream=new FileInputStream("C:\\Users\\DMarsh\\Desktop\\Programming II\\data.txt");
    	     		DataInputStream in= new DataInputStream (fstream);
    	     		BufferedReader br=new BufferedReader (new InputStreamReader (in));
    	     		String strLine;
    	     		while ((strLine=br.readLine())!= null){
    	     			System.out.println(strLine);
    	     			
    	     		}
    	     			in.close();
    
    	     	}catch (Exception e){
    	     		System.err.println("Error: " + e.getMessage());
    	     	}
    
    
    	     }
    	 }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Simple Text File Editing in Java help

    For text files you'll probably want to use a writer such as a PrintWriter. I've heard that it's best to write to a temp file first, and only when done and no errors occur, to rename it to the file you want to over-write.

Similar Threads

  1. way to catch if file is simple text based
    By Jovaras in forum New To Java
    Replies: 6
    Last Post: 06-21-2011, 10:18 PM
  2. Editing text files
    By NickBru in forum New To Java
    Replies: 4
    Last Post: 12-05-2010, 06:27 PM
  3. Text editing
    By right2001 in forum New To Java
    Replies: 1
    Last Post: 04-10-2009, 07:03 AM
  4. Replies: 3
    Last Post: 12-12-2008, 12:12 PM

Posting Permissions

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