English 中文(简体)
指挥部
原标题:Command to locate a given directory

是否有任何(九)指挥能够找到某个局?

例如,我有一个名为“MyDir”的名录,但我不知道光盘上的绝对路径。 我是否掌握了通往我的迪尔的道路?

更具体地说,我要在 Java方案(通过系统电话)中这样做。

// return the full path to the specified directory
// if there s more than once directory with the given name
// just return the first one.
static String findPath (String dirName)
{
     // CODE here

}

感谢!

最佳回答

如果有(有些系统可能无法建立其指数),<代码>定位<>>>><>>指示将对照该系统上所有可世界阅读的目录中的档案路径进行细分。

问题回答

仅凭单,可使用> 定位。 Don tabes 定期操作updatedb,但(最好自动)。

为在 Java实际指挥线,检查,该条。 基本指挥是<代码>Runtime#exec,但你希望做一些错误检查。 The snippet provided in the article is:

import java.io.*;

public class JavaRunCommand {

    public static void main(String args[]) {

        String s = null;

        try {

        // run the Unix "ps -ef" command
            // using the Runtime exec method:
            Process p = Runtime.getRuntime().exec("ps -ef");

            BufferedReader stdInput = new BufferedReader(new 
                 InputStreamReader(p.getInputStream()));

            BufferedReader stdError = new BufferedReader(new 
                 InputStreamReader(p.getErrorStream()));

            // read the output from the command
            System.out.println("Here is the standard output of the command:
");
            while ((s = stdInput.readLine()) != null) {
                System.out.println(s);
            }

            // read any errors from the attempted command
            System.out.println("Here is the standard error of the command (if any):
");
            while ((s = stdError.readLine()) != null) {
                System.out.println(s);
            }

            System.exit(0);
        }
        catch (IOException e) {
            System.out.println("exception happened - here s what I know: ");
            e.printStackTrace();
            System.exit(-1);
        }
    }
}

否则,请。 穿孔树: (Java原住民使用NIO.2)。 这可能需要更长的时间,但因为时间不够。

As an alternative to the locate command (if, say, the required database isn t being maintained), you could use the find command:

find / -type d -name Foo

This invocation will find any directory named Foo anywhere under / on the filesystem. Note that this can be very, very slow - if locate is available, that ll probably perform much better.

实际定位指挥是

locate -r ~/".*"MyDir

and if needed to refresh db,

sudo updatedb




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签