Last active
February 26, 2023 00:03
-
-
Save sathishjayapal/399bef226eda44be70752cc415012c45 to your computer and use it in GitHub Desktop.
Boiler plate for Parsing filr
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
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