[英]How to set relative path of Unix server folder to save/create Excel file
當前,我正在這里使用Apache POI在Java代碼中用Excel編寫輸出,我將這個輸出Excel文件保存在本地驅動器中的某個位置。 現在的挑戰是,由於某些要求,我必須在Unix服務器上的某個目錄中保存/創建相同的Excel。
誰能建議如何為此編寫代碼?
如何在Java代碼中設置該Unix服務器目錄路徑?
String excelFileName = "D://TestResult_Output_Excel.xlsx";//name of excel file
保存Windows和Unix目標,並確保最后保存路徑分隔符(對於Windows,為/
;對於Windows,為\\\\
)
String fileName = "TestResult_Output_Excel.xlsx"
String windowsFilePath = "D:\\outputfolder\\"
String unixFilePath = "/home/foo/folder/"
獲取程序正在運行的操作系統名稱
String OS = System.getProperty("os.name");
將其與您的OS選項進行比較(在這種情況下為Windows / UNIX)
String outputFilePath;
if (OS.toUpperCase().contains("WINDOWS")) {
outputFilePath = windowsFilePath;
} else {
outputFilePath = unixFilePath;
}
如果需要動態文件名,則可以在此時添加它,也可以將其添加到原始路徑變量中。
outputFilePath += fileName;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.