Skip to content

Instantly share code, notes, and snippets.

@sathishjayapal
Last active February 26, 2023 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sathishjayapal/399bef226eda44be70752cc415012c45 to your computer and use it in GitHub Desktop.
Save sathishjayapal/399bef226eda44be70752cc415012c45 to your computer and use it in GitHub Desktop.
Boiler plate for Parsing filr
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
class Scratch {
private static final Logger logger = LoggerFactory.getLogger(Scratch.class);
public File getDefaultFile() {
return defaultFile;
}
public void setDefaultFile(File defaultFile) {
this.defaultFile = defaultFile;
}
File defaultFile;
public static void main(String[] args) {
if (args.length > 0) {
Scratch scratch = new Scratch();
scratch.setDefaultFile(new File(args[0]));
BufferedReader reader = null;
StringBuilder builder = new StringBuilder();
try {
reader = new BufferedReader(new FileReader(scratch.getDefaultFile()));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line).append("\n");
}
System.out.println("Output of Default File" + builder.toString());
} catch (IOException io) {
logger.error("IO Exception parsing file " + io.toString());
} finally {
if (reader != null) {
try {
reader.close();
} catch (Exception exception) {
logger.error("Exception in finally block " + exception.getMessage());
}
}
}
} else {
System.out.println("Cannot go anywhere without filename");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment