By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,474 Members | 3,141 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,474 IT Pros & Developers. It's quick & easy.

java as/400 ifs question

P: n/a
Hi, all! Here's my question. There is a way to program
to copy a file from one directory to another on the AS/400 using the
installable file system classes(here's the ibm.s code folows)

My problem is that I need to copy files from NT network to as/400 ifs.
Please, give me some hints of how to use the existing code (this is my very
first java assignment)
//Thanks in advance and please, cc: your reply to my e-mail:
ta********@yahoo.ca
NT

import java.io.*;
import java.util.*;
import com.ibm.as400.access.*;

public class IFSCopyFile extends Object
{
public static void main(String[] parameters)
{
System.out.println( " " );

String sourceName = "";
String targetName = "";
String system = "";
byte[] buffer = new byte[1024 * 64];

IFSFileInputStream source = null;
IFSFileOutputStream target = null;

// if all three parameters were not specified, display help text and
exit.

if (parameters.length > 2)
{

// Assume the first parameter is the system name,
// the second parameter is the source name and
// the third parameter is the target name.

system = parameters[0];
sourceName = parameters[1];
targetName = parameters[2];

try
{
// Create an AS400 object for the AS/400 system that holds the
files.

AS400 as400 = new AS400(system);

// Open the source file for exclusive access.

source = new IFSFileInputStream(as400,
sourceName,
IFSFileInputStream.SHARE_NONE);

System.out.println("Source file successfully opened");

// Open the target file for exclusive access.

target = new IFSFileOutputStream(as400,
targetName,
IFSFileOutputStream.SHARE_NONE,
false);

System.out.println("Target file successfully opened");

// Read the first 64K bytes from the source file.

int bytesRead = source.read(buffer);

// While there is data in the source file copy the data from
// the source file to the target file.

while (bytesRead > 0)
{
target.write(buffer, 0, bytesRead);
bytesRead = source.read(buffer);
}

System.out.println("Data successfully copied");

// Clean up by closing the source and target files.

source.close();
target.close();

// Get the last changed date/time from the source file and
// set it on the target file.

IFSFile src = new IFSFile(as400, sourceName);
long dateTime = src.lastModified();

IFSFile tgt = new IFSFile(as400, targetName);
tgt.setLastModified(dateTime);

System.out.println("Date/Time successfully set on target file");
System.out.println("Copy Successful");

}
catch (Exception e)
{
// If any of the above operations failed say the copy failed
// and output the exception.

System.out.println("Copy failed");
System.out.println(e);
}
}

// Display help text when parameters are incorrect.

else
{
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("Parameters are not correct. Command syntax
is:");
System.out.println("");
System.out.println(" IFSCopyFile as400 source target");
System.out.println("");
System.out.println("Where");
System.out.println("");
System.out.println(" as400 = system that contains the files");
System.out.println(" source = source file in /path/path/name
format");
System.out.println(" target = target file in /path/path/name
format");
System.out.println("");
System.out.println("For example:");
System.out.println("");
System.out.println(" IFSCopyFile myAS400 /dir1/dir2/a.txt
/dir3/b.txt");
System.out.println("");
System.out.println("");
}

System.exit(0);
}
}
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.