JavaFX目录选择器 - 如何从目录获取路径?

时间:2017-12-05 13:34:49

标签: java javafx nullpointerexception directory

我想从带有DirectoryChooser的目录中获取路径。我的代码看起来像这样:

DirectoryChooser dc = new DirectoryChooser();
dc.showDialog(stage);
File f = dc.getInitialDirectory();
String s = f.getAbsolutePath();
System.out.println(s);

但那不起作用,有人可以帮助我吗?方法getInitialDirectory()始终为null

1 个答案:

答案 0 :(得分:8)

看起来应该是这样的:

def heapify(arr, n, i):
    count = 0
    largest = i  
    l = 2 * i + 1     
    r = 2 * i + 2     
    if l < n and arr[i] < arr[l]:
        largest = l
    if r < n and arr[largest] < arr[r]:
        largest = r
    if largest != i:
        count += 1
        arr[i],arr[largest] = arr[largest],arr[i]
        count += heapify(arr, n, largest)
    return count

def heapSort(arr):
    n = len(arr)
    count = 0
    for i in range(n, -1, -1):
        heapify(arr, n, i)  
        count += heapify(arr, i, 0)
    for i in range(n-1, 0, -1):
        arr[i], arr[0] = arr[0], arr[i] 
        count += heapify(arr, i, 0)
    return count

更多信息:example of DirectoryChooser