Skip to content

Instantly share code, notes, and snippets.

@akshar100
Created August 30, 2013 22:32
Show Gist options
  • Save akshar100/6394938 to your computer and use it in GitHub Desktop.
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.
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