Illegal char <:> at index 2: /D:/kotlintworkspace解决办法

本文介绍了一个关于读取JSON文件时遇到的非法字符异常问题及解决方案。通过修改文件路径的处理方式,成功避免了异常的发生,确保了程序可以正确地解析JSON文件。
fun findRiOrders(): List<PlatformRiOrder> {
	val riPath = ClassLoaderUtils.getDefaultClassLoader().getResource("NewBillTestDataRiOrders.json")!!.path
	return objectMapper.readValue(Path(riPath).toFile())
}

IDEA报错信息


Illegal char <:> at index 2: /D:/kotlintworkspace/fastone-billing/services/billing-mgr/build/resources/test/NewBillTestDataRiOrders.json
java.nio.file.InvalidPathException: Illegal char <:> at index 2: /D:/kotlintworkspace/fastone-billing/services/billing-mgr/build/resources/test/NewBillTestDataRiOrders.json
	at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
	at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
	at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
	at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
	at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:232)
	at java.base/java.nio.file.Path.of(Path.java:147)
	at java.base/java.nio.file.Paths.get(Paths.java:69)
	at com.fastonetech.billing.bill.domain.NewBillTestKt.findRiOrders(NewBillTest.kt:89)
	at com.fastonetech.billing.bill.domain.NewBillTest$1$3.invokeSuspend(NewBillTest.kt:71)
	at com.fastonetech.billing.bill.domain.NewBillTest$1$3.invoke(NewBillTest.kt)
	at com.fastonetech.billing.bill.domain.NewBillTest$1$3.invoke(NewBillTest.kt)
	at io.kotest.core.internal.ExecutionsKt$executeWithBehaviours$2$1.invokeSuspend(executions.kt:13)
	at io.kotest.core.internal.ExecutionsKt$executeWithBehaviours$2$1.invoke(executions.kt)
	at io.kotest.core.internal.ExecutionsKt.wrapTestWithGlobalAssert(executions.kt:39)
	at io.kotest.core.internal.ExecutionsKt$executeWithBehaviours$2.invokeSuspend(executions.kt:12)
	at io.kotest.core.internal.ExecutionsKt$executeWithBehaviours$2.invoke(executions.kt)
	at io.kotest.core.internal.ExecutionsKt$wrapTestWithAssertionModeCheck$2.invokeSuspend(executions.kt:25)
	at io.kotest.core.internal.ExecutionsKt$wrapTestWithAssertionModeCheck$2.invoke(executions.kt)
	at io.kotest.core.internal.AssertionsCheckKt.executeWithAssertionsCheck(assertionsCheck.kt:25)
	at io.kotest.core.internal.ExecutionsKt.wrapTestWithAssertionModeCheck(executions.kt:24)
	at io.kotest.core.internal.ExecutionsKt.executeWithBehaviours(executions.kt:11)
	at io.kotest.core.internal.TestCaseExecutor$executeInScope$2.invokeSuspend(TestCaseExecutor.kt:266)
	at io.kotest.core.internal.TestCaseExecutor$executeInScope$2.invoke(TestCaseExecutor.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
	at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264)
	at io.kotest.core.internal.TestCaseExecutor.executeInScope(TestCaseExecutor.kt:260)
	at io.kotest.core.internal.TestCaseExecutor$executeAndWait$2$1$1$3$1$1.invokeSuspend(TestCaseExecutor.kt:232)
	at io.kotest.core.internal.TestCaseExecutor$executeAndWait$2$1$1$3$1$1.invoke(TestCaseExecutor.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturnIgnoreTimeout(Undispatched.kt:100)
	at kotlinx.coroutines.TimeoutKt.setupTimeout(Timeout.kt:148)
	at kotlinx.coroutines.TimeoutKt.withTimeout(Timeout.kt:44)
	at io.kotest.core.internal.TestCaseExecutor$executeAndWait$2$1$1$3$1.invokeSuspend(TestCaseExecutor.kt:231)
	at io.kotest.core.internal.TestCaseExecutor$executeAndWait$2$1$1$3$1.invoke(TestCaseExecutor.kt)
	at io.kotest.engine.ExecutorExecutionContext$executeWithTimeoutInterruption$3.invokeSuspend(ExecutorExecutionContext.kt:77)
	at io.kotest.engine.ExecutorExecutionContext$executeWithTimeoutInterruption$3.invoke(ExecutorExecutionContext.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:165)
	at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
	at io.kotest.engine.ExecutorExecutionContext.executeWithTimeoutInterruption(ExecutorExecutionContext.kt:75)
	at io.kotest.core.internal.TestCaseExecutor$executeAndWait$2$1$1$3.invokeSuspend(TestCaseExecutor.kt:230)
	at io.kotest.core.internal.TestCaseExecutor$executeAndWait$2$1$1$3.invoke(TestCaseExecutor.kt)
	at io.kotest.mpp.ReplayKt.replay(replay.kt:18)
	at io.kotest.core.internal.TestCaseExecutor$executeAndWait$2$1$1.invokeSuspend(TestCaseExecutor.kt:225)
	at io.kotest.core.internal.TestCaseExecutor$executeAndWait$2$1$1.invoke(TestCaseExecutor.kt)
	at io.kotest.engine.ExecutorExecutionContext$executeWithTimeoutInterruption$3.invokeSuspend(ExecutorExecutionContext.kt:77)
	at io.kotest.engine.ExecutorExecutionContext$executeWithTimeoutInterruption$3.invoke(ExecutorExecutionContext.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:165)
	at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
	at io.kotest.engine.ExecutorExecutionContext.executeWithTimeoutInterruption(ExecutorExecutionContext.kt:75)
	at io.kotest.core.internal.TestCaseExecutor$executeAndWait$2$1.invokeSuspend(TestCaseExecutor.kt:218)
	at io.kotest.core.internal.TestCaseExecutor$executeAndWait$2$1.invoke(TestCaseExecutor.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturnIgnoreTimeout(Undispatched.kt:100)
	at kotlinx.coroutines.TimeoutKt.setupTimeout(Timeout.kt:148)
	at kotlinx.coroutines.TimeoutKt.withTimeout(Timeout.kt:44)
	at io.kotest.core.internal.TestCaseExecutor$executeAndWait$2.invokeSuspend(TestCaseExecutor.kt:217)
	at io.kotest.core.internal.TestCaseExecutor$executeAndWait$2.invoke(TestCaseExecutor.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
	at kotlinx.coroutines.SupervisorKt.supervisorScope(Supervisor.kt:61)
	at io.kotest.core.internal.TestCaseExecutor.executeAndWait(TestCaseExecutor.kt:213)
	at io.kotest.core.internal.TestCaseExecutor.invokeTestCase(TestCaseExecutor.kt:182)
	at io.kotest.core.internal.TestCaseExecutor.executeActiveTest(TestCaseExecutor.kt:151)
	at io.kotest.core.internal.TestCaseExecutor$intercept$innerExecute$1$1.invokeSuspend(TestCaseExecutor.kt:89)
	at io.kotest.core.internal.TestCaseExecutor$intercept$innerExecute$1$1.invoke(TestCaseExecutor.kt)
	at io.kotest.core.internal.TestCaseExecutor.executeIfActive(TestCaseExecutor.kt:115)
	at io.kotest.core.internal.TestCaseExecutor$intercept$innerExecute$1.invokeSuspend(TestCaseExecutor.kt:89)
	at io.kotest.core.internal.TestCaseExecutor$intercept$innerExecute$1.invoke(TestCaseExecutor.kt)
	at io.kotest.core.internal.TestCaseExecutor.intercept(TestCaseExecutor.kt:103)
	at io.kotest.core.internal.TestCaseExecutor.execute(TestCaseExecutor.kt:69)
	at io.kotest.engine.spec.runners.InstancePerTestSpecRunner$run$2.invokeSuspend(InstancePerTestSpecRunner.kt:155)
	at io.kotest.engine.spec.runners.InstancePerTestSpecRunner$run$2.invoke(InstancePerTestSpecRunner.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
	at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264)
	at io.kotest.engine.spec.runners.InstancePerTestSpecRunner.run(InstancePerTestSpecRunner.kt:119)
	at io.kotest.engine.spec.runners.InstancePerTestSpecRunner.interceptAndRun(InstancePerTestSpecRunner.kt:113)
	at io.kotest.engine.spec.runners.InstancePerTestSpecRunner.executeInCleanSpec(InstancePerTestSpecRunner.kt:104)
	at io.kotest.engine.spec.runners.InstancePerTestSpecRunner$execute$$inlined$invoke$lambda$2.invokeSuspend(InstancePerTestSpecRunner.kt:82)
	at io.kotest.engine.spec.runners.InstancePerTestSpecRunner$execute$$inlined$invoke$lambda$2.invoke(InstancePerTestSpecRunner.kt)
	at io.kotest.engine.launchers.SequentialTestLauncher$launch$$inlined$forEach$lambda$1$1.invokeSuspend(SequentialTestLauncher.kt:22)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)

修改后的代码:

fun findRiOrders(): List<PlatformRiOrder> {
	val riPath = ClassLoaderUtils.getDefaultClassLoader().getResource("NewBillTestDataRiOrders.json")!!.toURI()
	return objectMapper.readValue(Paths.get(riPath).toFile())
}
给定的参考引用中未提及在PyCharm中出现 'Illegal char <:> at index 5: https://127.0.0.1:8000' 错误的解决方案。不过,通常这种错误可能是由于路径、URL 处理不当或者配置错误导致的,以下是一些可能的解决办法: ### 检查运行配置 在 PyCharm 中,运行配置可能会包含错误的 URL 或者路径。需要检查运行配置里的 URL 是否正确,避免出现非法字符。具体步骤为: 1. 打开“Run”菜单,选择“Edit Configurations”。 2. 在“Configurations”列表中,选择当前的运行配置。 3. 检查“Script path”、“Parameters”等字段,确保没有包含非法字符或者错误的 URL。 ### 检查代码中的 URL 如果代码里有使用 URL,要确保 URL 的格式正确。例如,在 Python 代码中使用 `requests` 库发送请求时: ```python import requests url = 'https://127.0.0.1:8000' try: response = requests.get(url) print(response.text) except requests.exceptions.RequestException as e: print(f"An error occurred: {e}") ``` 在这个例子中,要保证 URL 格式正确,避免出现非法字符。 ### 检查 PyCharm 版本 有时候,这种错误可能是 PyCharm 的版本问题导致的。可以尝试更新 PyCharm 到最新版本,看看问题是否解决。 ### 检查操作系统路径分隔符 不同操作系统使用的路径分隔符不同,Windows 使用反斜杠 `\`,而 Linux 和 macOS 使用正斜杠 `/`。确保在代码和配置中使用正确的路径分隔符。 ### 清除缓存 有时候,PyCharm 的缓存文件可能会导致一些奇怪的问题。可以尝试清除 PyCharm 的缓存,具体步骤如下: 1. 关闭 PyCharm。 2. 找到 PyCharm 的缓存目录,一般在用户目录下的 `.PyCharm<version>/system/caches` 文件夹。 3. 删除该文件夹下的所有文件。 4. 重新启动 PyCharm。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MonkeyKing.sun

对你有帮助的话,可以打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值