Mac 和 Windows 上存储文件的常见位置
我正在编写一个需要保存文件的java代码。
以下代码适用于 Mac。
ImageIO.write(movie_image, "jpg",new File("/Users/sathyap/Desktop/movieimages/"+文件名+".jpg"));
有没有办法可以给出目录结构“/Users/sathyap/Desktop/movieimages/” 硬编码适用于 Mac 和 Windows。
am writing a java code that needs to save a file.
the below code is for mac.
ImageIO.write(movie_image, "jpg",new File("/Users/sathyap/Desktop/movieimages/"+fileName+".jpg"));
is there a way i can give the directory structure "/Users/sathyap/Desktop/movieimages/"
hardcoded that works for both mac and windows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设该程序在 Mac 和 Windows 中的目录 (X) 下运行。您可以这样编码:
File.separator 将处理平台...您的文件将始终保存在当前工作目录下...您可以提供访问这些路径的快捷方式并将它们放在桌面上
如果用户可以执行写入该目录的程序...我假设用户也可以毫无问题地访问这些文件
Assuming that the program runs under a directory (X) in either Mac and Windows. You can code it like this:
File.separator will take care of platform ... your files will always be saved under current working direcoty ... you can provide shortcuts to access those paths and place them on desktop
If a user can execute the program that writes to that directory ... I will assume that the user can also access the files without problem
编辑:完全改变我的答案,因为我认为您正在寻找的是坚持跨平台而不是分别针对每种情况进行编码。
EDIT: Totally changing my answer because I think what you're looking for is sticking to cross-platform rather than coding for each situation separately.