public static void Main (string[] args) throws IOException {
list<object[]> rows = new arraylist<object[]> ();
String FilePath = "d:\\ development plan \\test\\";
String fileName = "Datasoure";
for (int i=0;i<10000;i++) {
Random rd = new random ();
int in = Rd.nextint () *10000+1;
String out = string.valueof (in). SUBSTRING (1, 6);
String Plateno = "Zhe a" +out;
String Vehicleframeno = "lj12ekr25f4r" +out;
String Engineno = "Lj12ek" +out;
SimpleDateFormat format = new SimpleDateFormat ("Yyyymmddhhmmss");
String Payflowid = "A" +format.format (New Date ()) +out;
String[] Array = {Plateno, ",", Vehicleframeno, ",", Engineno, ",", payflowid};
Rows.Add (array);
}
Boolean a = Createtxtfile (Rows,filepath,filename);
System.out.println (a);
}
/**
Generated. TXT format file with almost unlimited number of lines
*/
public static Boolean Createtxtfile (list<object[]> rows, String FilePath, String fileName) {
Mark whether the file was generated successfully
Boolean flag = true;
try {
Full path with file name
String FullPath = filePath + file.separator + fileName + ". txt";
File File = new file (FullPath);
if (file.exists ()) {//If it already exists, delete the old file
File.delete ();
}
File = new file (FullPath);
File.createnewfile ();
Traverse output per line
PrintWriter PFP = new PrintWriter (file);
For (object[] rowdata:rows) {
StringBuffer thisline = new StringBuffer ("");
for (int i = 0; i < rowdata.length; i++) {
Object obj = rowdata[i]; Current Field
Formatting data
String field = "";
if (null! = obj) {
if (obj.getclass () = = String.class) {//If it is a string
field = (String) obj;
}
} else {
field = ""; Give a space placeholder when null
}
Stitching all fields with one row of data, using the TAB key to separate
if (I < rowdata.length-1) {//not the last element
Thisline.append (field);
} else {//is the last element
Thisline.append (field);
}
}
Pfp.print (thisline.tostring () + "\ n");
}
Pfp.close ();
} catch (Exception e) {
Flag = false;
E.printstacktrace ();
}
return flag;
}
Java generates pressure measurement data