Java文件路径Windows / Linux [英] Java File Path Windows/Linux

查看:135
本文介绍了Java文件路径Windows / Linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为这两个操作系统在Java中创建文件路径的最佳解决方案是什么。应用程序将用于此操作系统,我需要创建通用字符串。

what is the best solution to create file path in Java for this two OS. Application will be used for this os , the i need to create universal String.

例如:
对于Linux:

for example : For Linux:

public File folderTxt = new File("/home/romankooo/work/txt/");

对于Windows:

public File folderTxt = new File("C:\\PDFMalwareDataAnalyser\\Txt\\");

或者是为此操作系统生成2 .jar文件的最佳解决方案。

Or is the best solution to generate 2 .jar files for this OS.

非常感谢。

推荐答案

最好的事情是让java为你决定喜欢这个

The best thing is to let java decide that for you like this

    public File folderTxt = new File(File.separator + "home" + File.separator + "romankooo" + File.separator + "work" + File.separator + "txt" + File.separator);

这篇关于Java文件路径Windows / Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆