Last active
December 14, 2015 22:58
-
-
Save ryasmi/5161866 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
public class FilterTextFile { | |
public static void main(String[] args) throws FileNotFoundException { | |
Scanner fScan, cScan = new Scanner(System.in); | |
String inFile, outFile, findStr; | |
FileInputStream fileInput; | |
PrintWriter fileOutput; | |
// Get input file. | |
System.out.print("Input file ? "); | |
inFile = cScan.nextLine(); | |
fileInput = new FileInputStream(inFile); | |
fScan = new Scanner(fileInput); | |
// Get output file. | |
System.out.print("Output file ? "); | |
outFile = cScan.nextLine(); | |
fileOutput = new PrintWriter(outFile); | |
// Get search string. | |
System.out.print("String to search for ? "); | |
findStr = cScan.nextLine(); | |
// Filter input file to output file. | |
while (fScan.hasNextLine()) { | |
String line = fScan.nextLine(); | |
if (line.contains(findStr)) { | |
fileOutput.println(line); | |
} | |
} | |
fileOutput.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment