litesoft
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt
package org.litesoft.util;
import java.io.*;
public class FileReplacer extends AbstractFileAR
{
public static final String VERSION = "1.2";
public static void main( String[] args )
throws Exception
{
new FileReplacer().process( "FileReplacer", VERSION, args );
}
/**
* Move Dir - Assume same volume!
*/
@Override
protected boolean moveDir( File pSource, File pDestination )
{
DirectoryUtils.deleteIfExists( pDestination );
DirectoryUtils.moveFile( pSource, pDestination );
return true;
}
/**
* Move File - Assume same volume!
*/
@Override
protected boolean moveFile( File pSource, File pDestination )
{
FileUtils.deleteIfExists( pDestination );
DirectoryUtils.moveFile( pSource, pDestination );
return true;
}
/**
* Update the existing pDestination from the pSource - Assume NOT the same volume!
*/
@Override
protected boolean updateFile( File pSource, File pDestination )
{
String[] srcLines = FileUtils.loadTextFile( pSource );
String[] dstLines = FileUtils.loadTextFile( pDestination );
if ( !Utils.areArraysEqual( srcLines, dstLines ) )
{
FileUtils.deleteIfExists( pDestination );
FileUtils.storeTextFile( pDestination, srcLines );
return true;
}
return false;
}
/**
* Copy the pSource to the pDestination - Assume NOT the same volume!
*/
@Override
protected boolean copyAddFile( File pSource, File pDestination )
{
FileUtils.storeTextFile( pDestination, FileUtils.loadTextFile( pSource ) );
return true;
}
}
|