Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import javax.swing.JFileChooser;
- import javax.swing.filechooser.FileNameExtensionFilter;
- public class Main {
- static ArrayList<String> txt = new ArrayList<String>();
- static ArrayList<String> temp = new ArrayList<String>();
- static File selectFile;
- public static void main(String[] args) throws IOException {
- InputStreamReader input = new InputStreamReader(System.in);
- BufferedReader inp = new BufferedReader(input);
- System.out.println("Insert the file directory of the txt: ");
- inp.readLine();
- inp.close();
- JFileChooser chooser = new JFileChooser();
- FileNameExtensionFilter filter = new FileNameExtensionFilter(
- "TXT Images", "txt");
- chooser.setFileFilter(filter);
- if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
- {
- selectFile = chooser.getSelectedFile();
- }
- importTxt(selectFile);
- Reverse(txt);
- System.out.println(temp);
- }
- @SuppressWarnings("resource")
- public static void importTxt(File file) throws IOException{
- BufferedReader in;
- in = new BufferedReader(new FileReader(file));
- while (in.readLine() != null){
- txt.addAll(Arrays.asList(in.readLine().split(" ")));
- }
- in.close();
- }
- public static void Reverse(ArrayList<String> txt){
- for(int i = txt.size() - 1; i == 0; i--){
- temp.add(txt.get(i));
- }
- }
- }
Add Comment
Please, Sign In to add comment