搜索文件内容
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
默认情况下,查询会同时搜索文件路径和内容。您可以使用 content
过滤条件将搜索范围限制为仅搜索文件内容。例如,以下查询在所有 Java 文件的内容中查找术语 main
。它不会搜索路径中包含术语 main
的实例。
lang:java content:main
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eThe default search includes both file paths and file content.\u003c/p\u003e\n"],["\u003cp\u003eFor content-only searches, use the \u003ccode\u003econtent\u003c/code\u003e filter, like \u003ccode\u003econtent:main\u003c/code\u003e to find "main" within Java files.\u003c/p\u003e\n"],["\u003cp\u003eThis approach avoids irrelevant results from file paths containing the search term.\u003c/p\u003e\n"]]],[],null,["# Searching file contents\n\nBy default, a query searches both the file path and the content. You can\nrestrict your search to just the contents of a file by using the\n[`content`](../reference#filters) filter. For example, the following query looks\nfor the term `main` in the contents of all Java files. It does not search for\ninstances where a path contains the term `main`. \n\n lang:java content:main"]]