Skip to content

Commit

Permalink
Now using JFileChooser
Browse files Browse the repository at this point in the history
This will make things faster
  • Loading branch information
Dexer125 committed Jun 2, 2020
1 parent 578c024 commit 705ec7e
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/com/dexer125/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.dexer125;

import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.filechooser.FileSystemView;
import java.awt.*;
import java.io.*;
import java.time.LocalDateTime;
Expand All @@ -16,7 +19,7 @@ public static void main(String[] args) throws IOException {
private static void ReadDenialsFromFile() throws IOException {
//Initialize values
BufferedReader reader;
String path;
String path = "";
String outPath;
String command;
String scontext;
Expand All @@ -35,8 +38,26 @@ private static void ReadDenialsFromFile() throws IOException {
while (answer.equals("y")) {
//Ask for paths
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the path to log file: ");
path = scanner.nextLine();
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
JFileChooser jfc = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());
jfc.setDialogTitle("Select a text file");
jfc.setAcceptAllFileFilterUsed(false);
FileNameExtensionFilter filter = new FileNameExtensionFilter("Text files", "txt");
jfc.addChoosableFileFilter(filter);

int returnValue = jfc.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
path = jfc.getSelectedFile().getPath();
}else if (returnValue == JFileChooser.CANCEL_OPTION){
System.out.println("\nNo file selected, ending script...");
System.out.println("\nTool by @Dexer125");
return;
}

System.out.println("Would you like to save output into same path? y/n");
answer = scanner.nextLine();
if (answer.equals("y")) {
Expand Down Expand Up @@ -203,7 +224,6 @@ else if (answer.equals("n")) {

}


private static void RemoveDuplicates(String outPath, String outpuTxt) throws IOException {
System.out.println("Removing duplicates...");
PrintWriter printWriter = new PrintWriter(outPath + outpuTxt + ".txt");
Expand Down Expand Up @@ -236,6 +256,7 @@ private static void RemoveDuplicates(String outPath, String outpuTxt) throws IOE
}

private static void OpenFile(String outpath, String outputTxt) throws IOException {

File file = new File(outpath + outputTxt +".txt");
Desktop desktop = Desktop.getDesktop();
desktop.open(file);
Expand Down

0 comments on commit 705ec7e

Please sign in to comment.