import java.io.*; import java.util.*;class TestDirectory { public static void main(String[] args) { if (args.length < 1) { System.out.println("over. You must input one parameter at least."); System.exit(0); } WorkClass r1 = new WorkClass(args[0]); Thread t1 = new Thread(r1); t1.start();
} }class WorkClass implements Runnable { String pathName; File myFile; Vector v1; public WorkClass(String path) { pathName = new String(path); v1 = new Vector(); v1.add(pathName); myFile = new File((String)v1.remove(0)); } public void run() { while(myFile.isDirectory() == true) { System.out.println("[" + myFile.getName() + "]"); String filenameList[] = myFile.list();
for(int i = 0; i < filenameList.length; i++) { File file = new File(pathName + "\\" + filenameList[i]); if (file.isDirectory()) { v1.add(new String(pathName + "\\" + filenameList[i])); } else if (filenameList[i].endsWith(".sql") == true) { try { BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(pathName + "\\" + filenameList[i]))); BufferedWriter out = new BufferedWriter (new OutputStreamWriter(new FileOutputStream(pathName + "\\" + filenameList[i] + ".bak"))); String sin, sout; sin = in.readLine(); while (sin != null) { if (sin.startsWith("REM") == true) { sout = "--" + sin; } else { sout = sin; } out.write(sout, 0, sout.length()); out.newLine(); sin = in.readLine(); } out.close(); in.close(); File fileBak = new File(pathName + "\\" + filenameList[i] + ".bak"); if (file.exists()) { file.delete(); }
import java.io.*;public class JavaIO { public static void main(String[] args) { String a = new String(), b = "hello"; System.out.println(a); System.out.println(b);/* try { BufferedWriter out = new BufferedWriter( new OutputStreamWriter( new FileOutputStream("c:\\aaa.txt"))); out.write("Hello,everyone bitch!"); out.close(); } catch(Exception e) { System.err.println(e); } finally { System.out.println("done."); }*/ try { RandomAccessFile raf = new RandomAccessFile("c:\\aaa.txt", "rw"); System.out.println(raf.length()); String s = raf.readLine(); // s.seek(1); // System.out.println(s); // System.out.println(raf.getFD()); raf.seek(raf.length()); raf.writeBytes("\n" + s); raf.close(); } catch(Exception e) { System.err.println(e); } } }
import java.io.*;public class MB2 { public static void main(String[] args) { if (args.length < 1) { System.out.println("over. You must input one parameter at least."); System.exit(0); } try { BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(args[0])));
BufferedWriter out = new BufferedWriter (new OutputStreamWriter(new FileOutputStream(args[0] + ".bak")));
int count = 0; String sin, sout, sout2, num; sin = in.readLine();
int first, last, off; while (sin != null) { sout = sin.trim(); first = 0; last = 0; off = 0; count = 0; first = sout.indexOf(' ', 0); if (first == -1) { sin = in.readLine(); continue; } while (first != -1) { last = first; first = sout.indexOf(' ',first + 1); } num = sout.substring(last + 1, sout.length()); first = sout.indexOf(' ', 0); last = sout.indexOf(' ',first + 1); sout2 = sout.substring(first + 1, last) + "[" + num + "]," + sout.substring(0, first) + "v(" + num + ")," ; first = last; last = sout.indexOf(' ',first + 1);
import java.util.*;class TestDirectory
{
public static void main(String[] args)
{
if (args.length < 1)
{
System.out.println("over. You must input one parameter at least.");
System.exit(0);
} WorkClass r1 = new WorkClass(args[0]); Thread t1 = new Thread(r1); t1.start();
}
}class WorkClass implements Runnable
{
String pathName;
File myFile;
Vector v1;
public WorkClass(String path)
{
pathName = new String(path);
v1 = new Vector();
v1.add(pathName);
myFile = new File((String)v1.remove(0));
} public void run()
{
while(myFile.isDirectory() == true)
{
System.out.println("[" + myFile.getName() + "]");
String filenameList[] = myFile.list();
for(int i = 0; i < filenameList.length; i++)
{
File file = new File(pathName + "\\" + filenameList[i]); if (file.isDirectory())
{
v1.add(new String(pathName + "\\" + filenameList[i]));
}
else if (filenameList[i].endsWith(".sql") == true)
{
try
{
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(pathName + "\\" + filenameList[i])));
BufferedWriter out = new BufferedWriter (new OutputStreamWriter(new FileOutputStream(pathName + "\\" + filenameList[i] + ".bak"))); String sin, sout;
sin = in.readLine();
while (sin != null)
{
if (sin.startsWith("REM") == true)
{
sout = "--" + sin;
}
else
{
sout = sin;
} out.write(sout, 0, sout.length());
out.newLine();
sin = in.readLine();
} out.close();
in.close(); File fileBak = new File(pathName + "\\" + filenameList[i] + ".bak");
if (file.exists())
{
file.delete();
}
if (fileBak.exists())
{
fileBak.renameTo(file);
} System.out.println("\t" + filenameList[i] + "\t\t\t\t successful !");
}
catch(Exception e)
{
System.err.println(e);
}
}
} if (v1.isEmpty() == true)
{
System.out.println("program end.");
break;
}
else
{
pathName = (String)v1.remove(0);
myFile = new File(pathName);
}
}
}
}
{
public static void main(String[] args)
{
String a = new String(), b = "hello";
System.out.println(a);
System.out.println(b);/* try
{
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream("c:\\aaa.txt")));
out.write("Hello,everyone bitch!");
out.close();
}
catch(Exception e)
{
System.err.println(e);
}
finally
{
System.out.println("done.");
}*/ try
{
RandomAccessFile raf = new RandomAccessFile("c:\\aaa.txt", "rw");
System.out.println(raf.length());
String s = raf.readLine();
// s.seek(1);
// System.out.println(s);
// System.out.println(raf.getFD());
raf.seek(raf.length());
raf.writeBytes("\n" + s);
raf.close();
}
catch(Exception e)
{
System.err.println(e);
}
}
}
{
public static void main(String[] args)
{
if (args.length < 1)
{
System.out.println("over. You must input one parameter at least.");
System.exit(0);
} try
{
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(args[0])));
BufferedWriter out = new BufferedWriter (new OutputStreamWriter(new FileOutputStream(args[0] + ".bak")));
int count = 0;
String sin, sout, sout2, num; sin = in.readLine();
int first, last, off; while (sin != null)
{
sout = sin.trim(); first = 0;
last = 0;
off = 0;
count = 0; first = sout.indexOf(' ', 0);
if (first == -1)
{
sin = in.readLine();
continue;
}
while (first != -1)
{
last = first;
first = sout.indexOf(' ',first + 1);
} num = sout.substring(last + 1, sout.length());
first = sout.indexOf(' ', 0);
last = sout.indexOf(' ',first + 1); sout2 = sout.substring(first + 1, last) + "[" + num + "]," + sout.substring(0, first) +
"v(" + num + ")," ; first = last;
last = sout.indexOf(' ',first + 1);
sout2 += sout.substring(first + 1, last); out.write(sout2, 0, sout2.length());
out.newLine(); sin = in.readLine();
} out.close();
in.close(); File file1 = new File(args[0]);
if (file1.exists())
{
file1.delete();
} File file2 = new File(args[0] + ".bak");
if (file2.exists())
{
file2.renameTo(file1);
}
}
catch (Exception e)
{
System.err.println(e);
}
}
}