183 lines
6.2 KiB
HTML
183 lines
6.2 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html lang="en-us" xml:lang="en-us">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta name="security" content="public" />
|
||
|
<meta name="Robots" content="index,follow" />
|
||
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
||
|
<meta name="DC.Type" content="reference" />
|
||
|
<meta name="DC.Title" content="Example: Using IFS classes to copy a file from one directory to another" />
|
||
|
<meta name="abstract" content="" />
|
||
|
<meta name="description" content="" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="ifscopyfileexample" />
|
||
|
<meta name="DC.Language" content="en-us" />
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
||
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
||
|
<title>Example: Using IFS classes to copy a file from one directory to another</title>
|
||
|
</head>
|
||
|
<body id="ifscopyfileexample"><a name="ifscopyfileexample"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Example: Using IFS classes to copy a file from one directory to another</h1>
|
||
|
<div><p></p>
|
||
|
<div class="section"><div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm#codedisclaimer">Code
|
||
|
example disclaimer</a> for important legal information.</div>
|
||
|
<pre>//////////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// IFSCopyFile example. This program uses the installable file system classes
|
||
|
// to copy a file from one directory to another on the server.
|
||
|
//
|
||
|
// Command syntax:
|
||
|
// IFSCopyFile system sourceName TargetName
|
||
|
//
|
||
|
// For example,
|
||
|
// IFSCopyFile MySystem /path1/path2/file.ext /path3/path4/path5/file.ext
|
||
|
//
|
||
|
//////////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
|
||
|
|
||
|
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 server 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);
|
||
|
}
|
||
|
}</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</body>
|
||
|
</html>
|