Created
August 30, 2013 22:32
-
-
Save akshar100/6394938 to your computer and use it in GitHub Desktop.
Read all the files in the given directory. line by line and print the keyword and related text.
This file contains 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
package com.infoaxe.logprocessor; | |
import java.awt.List; | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import com.amazonaws.util.json.JSONException; | |
import com.amazonaws.util.json.JSONObject; | |
public class Main { | |
public static void main(String args[]) throws IOException { | |
// Directory path where s3 files are downloaded. | |
String path = "/mnt/soft/large/"; | |
String fileName; | |
File folder = new File(path); | |
File[] listOfFiles = folder.listFiles(); | |
for (int i = 0; i < listOfFiles.length; i++) { | |
if (listOfFiles[i].isFile()) { | |
fileName = listOfFiles[i].getName(); | |
BufferedReader br = new BufferedReader(new InputStreamReader( | |
new FileInputStream(listOfFiles[i]))); | |
String line = null; | |
while ((line = br.readLine()) != null) { | |
JSONObject json; | |
try { | |
json = new JSONObject(line); | |
//The keyword entered by the user | |
String searchedPhrase = json.getString("keyword"); | |
//The bag of words stripped of html tags | |
String response = json.getString("content"); | |
System.out.println(searchedPhrase); | |
System.out.println(response); | |
} catch (JSONException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment