|
Hi all,
I need to copy a file from my IFS to a PC which has a released directory via
SMB.
I use the following java-program on our AS400:
import java.io.*;
import java.util.*;
public class copy2david {
public static void copyFile(File inputFile, File outputFile, String
einfügen) throws IOException {
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
boolean einmal = false;
while ((c = in.read()) != -1) {
// ev. hier die @@ Angaben eintragen...
if (!einmal) {
/* klappt nicht
String suchwort = "7V";
String datei = in.toString();
// System.out.println("Substitute:" +
Substitute.substr(datei,suchwort, suchwort+einfügen));
*/
if (einfügen != null)
// angeforderten Text am Anfang in Zieldokument einfügen
out.write(einfügen);
einmal = true;
}
out.write(c);
}
in.close();
out.close();
}
public static void main(String[] args) {
File inputFile = null;
File outputFile = null;
// File sourcedir = new File("//10.10.11.200/bfsfax/*.OUT");
File sourcedir = new File("/home/BFSFax");
String zeile = "";
String einfügen = null;
if (args.length == 0) {
System.out.println("Keine Parameter übergeben. Kopiere alle
*.PCL Dokumente nach David.");
//System.out.println("Richtig währe z.B. copy2david
\"C:\\Test.PCL\" \"@@NUMMER 0281 670 9451@@\"");
//inputFile = new File("//10.10.11.200/bfsfax/Test.pcl");
einfügen = "" +
"@@NUMMER 0281 670 9451@@" +
"@@BENUTZER Herr Lorei@@" +
"@@BETREFF Mein Betreff@@" +
"";
} else {
inputFile = new File(args[0]);
if (args.length >= 2)
einfügen = args[1];
}
if(inputFile != null) {
// Datei angegeben
// zuerst Zieldokument mit Empfängerdaten für Tobit erzeugen
String outName = inputFile.getName();
String outPath = inputFile.getParent();
// Zieldateinamen ändern
outName = outName.substring(0, outName.length() -3);
outName = outName + "OUT";
outputFile = new File(outPath + "/" + outName);
try {
copyFile(inputFile, outputFile, einfügen);
System.out.println("Zieldatei " + outputFile + "
erstellt.");
//inputFile.delete();
System.out.println("Quelldatei " + inputFile + "
gelöscht.");
} catch( Exception e) {
System.out.println("Fehler beim kopieren von Datei " +
inputFile);
e.printStackTrace();
}
}
/*
* Kopiere nun alle *.OUT Dateien ins Zielverzeichnis
* (diese wurden bereits mit den Empfängerdaten für Tobit erstellt)
*/
File fi = sourcedir;
if (fi.exists()) {
if (!fi.isFile()) {
String[] dateien = fi.list();
System.out.println("dateien.length:" + dateien.length);
for (int i = 0; i < dateien.length; i++) {
// file ist eine Datei
// String outName = fi.getName();
String inName = dateien[i];
if (inName.endsWith(".OUT")) {
// PCL-Datei nach David kopieren
String outName = inName.substring(0, inName.length()
-3);
outName = outName + "PCL";
inputFile = new File(fi + "/" + inName);
// at my PC OK
// ! this makes a directory called
home\lorei\\\\\david\import\importPCL
// how can i copy to a remote ressource via
SMB-Network ??
outputFile = new
File("\\10.10.10.252\\david\\import\\importPCL\\" + outName);
//System.out.println("outName:" + outName);
try {
copyFile(inputFile, outputFile, null);
System.out.println("Zieldatei " + outputFile + "
erstellt.");
//inputFile.delete();
System.out.println("Quelldatei " + inputFile + "
gelöscht.");
}
catch( Exception e) {
System.out.println("Fehler beim kopieren von
Datei " + inputFile);
e.printStackTrace();
}
}
}
}
}
} // main
}
mit freundlichen Grüßen,
Stefan Lorei,
BYK-Chemie GmbH,
D - 46462 Wesel, Abelstraße 45
DV-Abteilung
Telefon: +049 281 670 451
Fax: +049 281 670 9451
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.