开发者

Making my program into a java file that can be used on other computers

开发者 https://www.devze.com 2023-03-24 21:41 出处:网络
This is what I have import java.io.File; import java.util.Scanner; public class Reader { static int spc_count = -1;

This is what I have

import java.io.File; import java.util.Scanner;

public class Reader {

    static int spc_count = -1;
    public static int count =0;



    public static void Process(File aFile) {
            spc_count++;
            String spcaces = "";
            for (int i = 0; i < spc_count; i++)
                    spcaces += " ";
            if (aFile.isFile() && aFile.getName().contains("mp3")) {
                    System.out.println(spcaces + "[FILE] " + aFile.getName());
                    count++;
            }

            else if (aFile.isDirectory()) {
                    System.out.println(spcaces + "[FOLDER NAME] " + aFile.getName());
                    File[] listOfFiles = aFile.listFiles();
                    if (listOfFiles != null) {
                            for (int i = 0; i < listOfFiles.length; i++)
                                    Process(listOfFiles[i]);
                    } else {
                            System.out.println(spcaces + " [ACCESS DENIED]");
                    }
            }
            spc_count--;

    }

    public static void main(String[] args) {

            System.out
                            .println("Please enter the directory path ");
            Scanner scanner = new Scanner(System.in);
            String Directory = scanner.nextLine();
            File aFile = new File(Directory);
            Process(aFile);
            System.out.println("\n" + Reader.count+ " MP3 files were found in this directory.");

    }

} What I want to do is to make it into a java file that I will be able to sh开发者_JAVA百科are with my friends and I would like it to prompt the user with a window to enter the directory and then display the output in a text file. I don't know if this is the best way to do this but any tips or suggestions on how to approach this would be appreciated.

Edit: Yes I want to create a executable jar file but I was having complications when creating a GUI. The problem that I had was when I wanted to output the name of the file to a text. What would be the best way to create a text file and have it show up when the code runs?


Create an executable jar.

Or even better (but a bit more work) you can distribute your app via Java Web Start.


You can compile the program with gcj and distribute the resulting executable.

0

精彩评论

暂无评论...
验证码 换一张
取 消