문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top