Web应用程序:将txt文件存储在来自Linux Web服务器的Windows服务器共享上

发布于 2024-09-09 15:46:31 字数 2864 浏览 4 评论 0原文

我有一个 java 类,用于从 Web 应用程序创建文本文件。我使用以下代码:

private void CreatePaymentFile(String QueryCriteria) {
BigDecimal TotalPay;
DecimalFormat df2 = new DecimalFormat("00000");
String RecordString = null;
try{
String fileName = "\\\\fileandprint\\Apps\\Jury\\SHARE\\Payment_" + shortdateToday + SeqID + "24400.txt";
File f = new File(fileName);
FileOutputStream fop = new FileOutputStream(f);
SetPaymentFileName("Payment_" + shortdateToday + SeqID + "24400.txt");
FileWriter PaymentStream = new FileWriter(fileName,true);
BufferedWriter out = new BufferedWriter(PaymentStream);

// TODO Auto-generated method stub
String RecordStringFormat = "%-220s%-3s%-4s%-3s%-5s%-5s%-5s%-5s%-30s%-287s%-10s%-150s%-1s%-30s%-1s%-80s%-10s%-6s%-6s%-10s%-20s%-5s%-12s%-43s%-2s%-10s%-70s%-3s%-1s%-1s%-10s%-4s%-6s%-10s%-10s%-5s%27s";
JurorPayDetails JurorpayDetails = new JurorPayDetails();
ArrayList<JurorPayDetails.JurorPayDetailsTable> JurorPayDetailsObjList = new ArrayList<JurorPayDetails.JurorPayDetailsTable>();
JurorpayDetails.setJurorPayDetailsSql("Select P.*, GroupAssignment, TermDateServed, LastName, FirstName, Street1, Street2, City, State, ZipCode, Mileage, PublicEmployee, PayTime, PayMiles from PayDetails P INNER JOIN Jurors J ON P.JurorID = J.JurorID INNER JOIN Address A ON J.JurorID = A.JurorID where AddressType = 'M' and J.TermDateServed IN (" + QueryCriteria +") ORDER BY GroupAssignment, LastName");
boolean indicator = JurorpayDetails.setListOfJurorPayDetails();

if (indicator == true)
{
int size = JurorpayDetails.getListSize();
JurorPayDetailsObjList = JurorpayDetails.getJurorPayDetailsList();
for (int i=0; i<size; ++i){
JurorPayDetails.JurorPayDetailsTable eachPayable = JurorPayDetails.JurorPayDetailsTable)JurorPayDetailsObjList.get(i);
TotalPay = eachPayable.HoursAmount.add(eachPayable.MilesAmount);
RecordString = String.format(RecordStringFormat, ((eachPayable.Street1.trim() + " " + eachPayable.Street2.trim()).trim()), "1","B","1","WFB10","00000","21801","21801",eachPayable.City,"",longdateToday,"", "N", "21801_" + eachPayable.JurorID,"N",((eachPayable.FirstName.trim() + " " + eachPayable.LastName.trim()).trim()),"",    "PYMTLD","0",longdateToday,"21801" + shortdateToday + SeqID,df2.format(i + 1),eachPayable.Zipcode,"","RE","0","","CHK","N", "Y",longdateToday,"PYMT",eachPayable.State, "","001","01200",Paymentdf.format(TotalPay));
out.append(RecordString);
out.newLine();
}
out.close();
}
}catch (Exception e) {
System.err.println("error: " + e.getMessage());
}
}

没什么大不了的,运行查询,获取结果并将其以固定格式写入文件并将其存储在我们的一台 Windows 服务器上。

这在本地运行时工作正常,但是,当我们将应用程序放在 Linux Web 服务器上(并将设置更改为 Linux)时,文件不会存储在正确的网络位置。

我尝试过使用 Windows 文件表示法和 Linux 文件表示法: \\fileandprint\Apps\Jury\SHARE\ 和 //fileandprint/Apps/Jury/SHARE/

是的,文件位置确实存在,正如我所说,当在开发中本地运行时它可以工作,只有当它在 Linux 机器上时它才不会正确存储文件。

有什么建议吗?

I have a java class that I use to create a text file from a web application. I'm using the following code:

private void CreatePaymentFile(String QueryCriteria) {
BigDecimal TotalPay;
DecimalFormat df2 = new DecimalFormat("00000");
String RecordString = null;
try{
String fileName = "\\\\fileandprint\\Apps\\Jury\\SHARE\\Payment_" + shortdateToday + SeqID + "24400.txt";
File f = new File(fileName);
FileOutputStream fop = new FileOutputStream(f);
SetPaymentFileName("Payment_" + shortdateToday + SeqID + "24400.txt");
FileWriter PaymentStream = new FileWriter(fileName,true);
BufferedWriter out = new BufferedWriter(PaymentStream);

// TODO Auto-generated method stub
String RecordStringFormat = "%-220s%-3s%-4s%-3s%-5s%-5s%-5s%-5s%-30s%-287s%-10s%-150s%-1s%-30s%-1s%-80s%-10s%-6s%-6s%-10s%-20s%-5s%-12s%-43s%-2s%-10s%-70s%-3s%-1s%-1s%-10s%-4s%-6s%-10s%-10s%-5s%27s";
JurorPayDetails JurorpayDetails = new JurorPayDetails();
ArrayList<JurorPayDetails.JurorPayDetailsTable> JurorPayDetailsObjList = new ArrayList<JurorPayDetails.JurorPayDetailsTable>();
JurorpayDetails.setJurorPayDetailsSql("Select P.*, GroupAssignment, TermDateServed, LastName, FirstName, Street1, Street2, City, State, ZipCode, Mileage, PublicEmployee, PayTime, PayMiles from PayDetails P INNER JOIN Jurors J ON P.JurorID = J.JurorID INNER JOIN Address A ON J.JurorID = A.JurorID where AddressType = 'M' and J.TermDateServed IN (" + QueryCriteria +") ORDER BY GroupAssignment, LastName");
boolean indicator = JurorpayDetails.setListOfJurorPayDetails();

if (indicator == true)
{
int size = JurorpayDetails.getListSize();
JurorPayDetailsObjList = JurorpayDetails.getJurorPayDetailsList();
for (int i=0; i<size; ++i){
JurorPayDetails.JurorPayDetailsTable eachPayable = JurorPayDetails.JurorPayDetailsTable)JurorPayDetailsObjList.get(i);
TotalPay = eachPayable.HoursAmount.add(eachPayable.MilesAmount);
RecordString = String.format(RecordStringFormat, ((eachPayable.Street1.trim() + " " + eachPayable.Street2.trim()).trim()), "1","B","1","WFB10","00000","21801","21801",eachPayable.City,"",longdateToday,"", "N", "21801_" + eachPayable.JurorID,"N",((eachPayable.FirstName.trim() + " " + eachPayable.LastName.trim()).trim()),"",    "PYMTLD","0",longdateToday,"21801" + shortdateToday + SeqID,df2.format(i + 1),eachPayable.Zipcode,"","RE","0","","CHK","N", "Y",longdateToday,"PYMT",eachPayable.State, "","001","01200",Paymentdf.format(TotalPay));
out.append(RecordString);
out.newLine();
}
out.close();
}
}catch (Exception e) {
System.err.println("error: " + e.getMessage());
}
}

not a big thing, run a query, get the results and write them in a fixed format to a file and store it on one of our Windows servers.

This works fine when run locally, however, when we put the application on the Linux web server (and change the settings to Linux), the files are not stored in the correct network location.

I have tried using Windows file notation and Linux file notation:
\\fileandprint\Apps\Jury\SHARE\
and
//fileandprint/Apps/Jury/SHARE/

and yes the file location does exist, as I said when run locally in development it works, only when it's on the Linux box does it not store the files correctly.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

您需要将网络共享显式挂载到本地目录中。请参阅 http://linuxwiki.de/smbmount 了解如何执行此操作的说明。

直接访问网络共享可以在 Gnome 和 KDE 文件管理器中使用,因为它们本身应用了一些魔法。在操作系统级别,这些路径不存在。

如果这不能解决问题,请附上异常输出。您可以更改

System.err.println("error: " + e.getMessage());

err.printStackTrace();

除了消息之外,这还将包括异常名称和堆栈跟踪。这特别有用,因为消息可能为空,并且您可以轻松查看代码的哪一行发生了异常。

you need to explicitly mount the network share into a local directory. Please see http://linuxwiki.de/smbmount for an explanation on how to do this.

Directly accessing the network share works in the Gnome and KDE file managers because they apply some magic themselves. On the operating system level those pathes don't exist.

If this does not solve the issue, please attach the exception output. You can change

System.err.println("error: " + e.getMessage());

to

err.printStackTrace();

This will include the exception name and stacktrace in addition to the message. This is especially helpful because the message may be null and you can easily see in which line of your code the exception occurred.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文