Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Make program search file in Java(I'd want to create a file search in Java that works on both Linux and Windows)
Make program search file in Java [message #1858038] Sun, 12 March 2023 17:18 Go to next message
bretny relly is currently offline bretny rellyFriend
Messages: 14
Registered: March 2023
Junior Member
I can write a file search software for Windows, but I know nothing about Linux. This logic is being used to display all of the discs in the windows.
package test;

import java.io.File;

public class Test {
public static void main(String[] args) {
    File[] drives = File.listRoots();
    String temp = "";
    for (int i = 0; i < drives.length; i++) {
        temp += drives[i];
    }

    String[] dir = temp.split("\\\\");
    for (int i = 0; i < dir.length; i++) {
        System.out.println(dir[i]);

    }
}
}


When used in Windows, the above code displays all of the roots such as c:, d:, and so on, but when used in Linux, it just displays /. I'm also using this reasoning to find a certain file in Windows.

public void findFile(String name,File file)
{
    File[] list = file.listFiles();
    if(list!=null)
    for (File fil : list)
    {
        if (fil.isDirectory())
        {
            findFile(name,fil);
        }
        else if (name.equalsIgnoreCase(fil.getName()))
        {
            System.out.println(fil.getParentFile());
        }
    }
}


It works good, but my difficulty is figuring out how to do it in Linux; I'm new to Linux and have no idea how to do it, and I'm running out of time; any assistance would be greatly appreciated.
Re: Make program search file in Java [message #1858044 is a reply to message #1858038] Mon, 13 March 2023 03:59 Go to previous messageGo to next message
Jay Arthanareeswaran is currently offline Jay ArthanareeswaranFriend
Messages: 128
Registered: July 2009
Senior Member
Hey, If I may offer my advise, you have better chances of getting a response on Stack overflow or other similar forums. This forum is specifically for the JDT component of Eclipse.
Re: Make program search file in Java [message #1858059 is a reply to message #1858044] Tue, 14 March 2023 00:02 Go to previous message
bretny relly is currently offline bretny rellyFriend
Messages: 14
Registered: March 2023
Junior Member
oh okay thank you
Previous Topic:Updating Maven Project never completes - Eclipse is hung
Next Topic:Any way to keep font preferences between workspaces?
Goto Forum:
  


Current Time: Fri Apr 26 11:15:33 GMT 2024

Powered by FUDForum. Page generated in 0.03245 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top