Kevin Keinert

+ Follow
since Aug 20, 2009
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kevin Keinert

Hi Sebastian,
This was my very first post, so please excuse my user unfriendly format. I don't know (yet) how to use code tags to make it more readable.

Also, I'm fairly new to programming.
I will research how to use the Java commands that you suggest. If you have any links to sample code or if you are willing to modify my code as an example to show me, it would be greatly appreciated.

Thanks for your time and help, Kevin.
12 years ago
I have a Java program that reads a singe text file, modifies it, and then saves it back into the same directory by appending "_Modified.txt" to the original filename. Code is attached below.

I want to modify this code so that instead of entering just a single filename, I instead enter a directory name. The Java program will then look into this directory and modify every file that it finds there. The files will all have the same type of text content and format, but the number of text files found in this directory can vary each time I run the program, and the filenames can be drastically different (not following any naming convention, other than ending with ".txt"). Every file in this directory will need to be modified each time the program is run.

Can someone please tell me how to modify this Java program so that is will look into a single directory, and modify every file that it finds there? As each text file is modified, I want to resave it (as before) by appending "_Modified.txt" to the original filename.

import java.util.Scanner;

class Kevins_File_Manipulator {

public static void main (String args []) throws IOException {
Scanner stdin = new Scanner (;
System.out.print ("File name to read from : ");
String inputFileName =;
Scanner sf = new Scanner (new File (inputFileName));
String outputFileName = inputFileName + "_Modified.txt";
System.out.println ("Opening for writing: " + outputFileName);
FileWriter fw = new FileWriter (outputFileName);
BufferedWriter bw = new BufferedWriter (fw);
PrintWriter pw = new PrintWriter (bw);
String line;
int count = 0;

// My code goes here that modifies each line of the text file and resaves it to the new file....

pw.close(); // finish and close the output text file

} // end main
} // end class
12 years ago