You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下运行Mac代码遇java.nio.file.InvalidPathException异常的解决

解决Windows下ParquetWriter路径非法字符异常

问题根源

异常提示路径file:/C:/Users/john/...中存在非法冒号,这是因为在Windows环境下,直接使用File.getPath()构造Hadoop Path对象时,会生成不符合Windows路径解析规范的URI格式(正确格式应为file:///C:/...),导致Java NIO的Windows路径解析器报错。

修复方案

修改代码中构造Hadoop Path的方式,改用File.toURI()获取符合规范的URI来创建Path对象:

原代码:

OutputFile outputFile = HadoopOutputFile.fromPath(new org.apache.hadoop.fs.Path(exportFile.getPath()), new Configuration());

修改后:

OutputFile outputFile = HadoopOutputFile.fromPath(new org.apache.hadoop.fs.Path(exportFile.toURI()), new Configuration());

原理说明

File.toURI()会生成符合URI标准的路径格式(Windows下为file:///C:/Users/...),Hadoop的Path类能正确识别该URI并转换为Windows本地文件系统可解析的路径,避免NIO解析时出现非法字符错误。

内容的提问来源于stack exchange,提问作者John Kwon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 01:57:06