Java generates pressure measurement data

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.