检查用户输入的文件名/路径是否有效
我试图让用户输入他想要保存某些内容的路径。 所以基本上我打开一个编辑器,让他输入路径...
但是我如何检查输入的字符串是否是有效的路径?
如果用户忘记在末尾输入“/” - 这不是问题,我可以手动检查...
但我无法手动检查所有内容:
末尾有一个空格(/文件夹/)
问号。
大于 - 小于符号 (/folder:->/
(back)slashes \folder\
以及所有这些东西
在 java 中有一种方便的方法来检查吗?
Possible Duplicate:
Is there a way in Java to determine if a path is valid without attempting to create a file?
I'm trying to let the user enter the path where he wants something to be saved.
so basically i open an editor, and let him enter the path...
but how can i check if the entered string is a valid path?
if the user forgets to type in a "/" at the end - its not a problem, i can manually check for that...
but i cant manually check for everything:
a space at the end (/folder /)
question marks.
greater than - less than symbols (/folder:->/
(back)slashes \folder\
and all that stuff
is there a convenient way in java to check for that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通用 Java 文件是一个目录或存在,来自 这个答案:
但是,Android(标记为 android 的问题),我必须研究一下......
Generic Java file is a directory or exists, from this answer:
However, Android (question tagged as android), I'll have to look into...