Wednesday, May 16, 2012

UNIX : Find files that contain a string

Ref for me..

find . -exec grep -l "string to find" {} \;
change the "string to find" to find your string. Please include (")

also can do this..
find . -type f | xargs grep "String to find"

Java : Create File


Source code for create file. Example : text.txt, sample.dat, etc..



import java.io.File;
import java.io.IOException;

public class MakeFile {
public static void main(String[] args) {
File myFile = new File("myJava.java"); //change this filename
try {
myFile.createNewFile();
} catch (IOException e) {
System.out.println("Cannot created.");
}
}
public String createFile(String fileName) {
File myFile = new File(fileName);
try {
myFile.createNewFile();
return "0:OK";
} catch (IOException e) {
System.out.println(e.getMessage());
return "1:Not OK";
}
}
}

save as MakeFile.java