Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions FileAnalyzer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @author William Hiranpat
* Analyze file extension and returns it. If there is no extension, let the user know that there is no extension.
*/

import java.io.file;

public class FileAnalyzer{
private static String fileAnalyze(File file) throws {
String extention = "";

if (file != null && file.exists()){
String name = file.getName();
extension = name.substring(name.lastIndexOf(".");)
}
else{
throw new NoExtensionException("No extension found.");
}

return extension;
}
}
38 changes: 38 additions & 0 deletions NoExtensionException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package file_organizer_gui;

import java.awt.Color;
import java.awt.Font;
import java.nio.file.Path;

import javax.swing.JFrame;
import javax.swing.JTextArea;

/**
* @@author William Hiranpat
* Exception that is thrown when the file has no extension
*/

public class NoExtensionException extends Exception{
private String message;
private String pathName;
private JFrame popUp;
private JTextArea buttonForException;

public NoExtensionException(String message){
this.message = message;
popUp = new JFrame("Extension not Found");
popUp.getContentPane().setBackground(Color.WHITE);
popUp.setBounds(500, 500, 500, 200);
popUp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
popUp.getContentPane().setLayout(null);

buttonForException = new JTextArea(message);
buttonForException.setFont(new Font("Times New Roman",Font.BOLD,24));
buttonForException.setBounds((int)popUp.getAlignmentX()/2, (int)popUp.getAlignmentY(), 500, 300);
popUp.getContentPane().add(buttonForException);
}

public void showExceptionPopUp() {
popUp.setVisible(true);
}
}