如何在java代码中获取此属性值?

如何在java代码中获取此属性值?,java,jsoup,Java,Jsoup,我正在学习Java,有时在从对象检索所需信息时遇到一些问题 调试代码时,我可以在targetFile中看到路径属性,但我不知道如何在代码中获得它 这是一个屏幕截图: (来源:) 这是我的完整代码: package com.example.helloworld; import com.github.axet.wget.WGet; import com.github.axet.wget.info.DownloadInfo; import org.jsoup.Jsoup; import org.j

我正在学习Java,有时在从对象检索所需信息时遇到一些问题

调试代码时,我可以在targetFile中看到路径属性,但我不知道如何在代码中获得它

这是一个屏幕截图:
(来源:)

这是我的完整代码:

package com.example.helloworld;

import com.github.axet.wget.WGet;
import com.github.axet.wget.info.DownloadInfo;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class HelloWorld {

    public static void main(String[] args) throws IOException {

        nodejs();

    }

    public static void nodejs() throws IOException {

        // Scrap the download url.
        Document doc = Jsoup.connect("http://nodejs.org/download").get();
        Element link = doc.select("div.interior:nth-child(2) > table:nth-child(2) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(3) > a:nth-child(1)").first();
        String url = link.attr("abs:href");

        // Print the download url.
        System.out.println(url);

        // Download file via the scraped url.
        URL download = new URL(url);
        File target = new File("/home/lan/Desktop/");
        WGet w = new WGet(download, target);
        w.download();

        // Get the targetFile property
        // ???

    }

}

如何获取此值?

我不知道您的代码,但您感兴趣的字段可能已封装,因此无法在代码中访问,但调试器可以在运行时看到它:)

更新:

该字段是默认包,您只能从包内访问它。
这有时会令人沮丧,但你应该问问自己,为什么这个类的设计者决定隐藏这个字段。

可能是Argh的重复,我使用wget是因为我想获得下载文件的完整路径,而不必像真正的wget那样强制使用文件名。我能做什么?不确定,但一种“快速且肮脏”的方法是复制WGet文件并使其成为您自己的文件来修改它们,这可能取决于许可证和您打算如何使用代码。我在Java方面没有足够的经验。。。你知道一个Java库可以做到这一点吗?我制作一个脚本,在Windows上下载并安装我最喜欢的软件。我尝试了多种编程语言的lib​​做我想做的事。恐怕你需要更多的Java经验,我没有时间全部解释。