Recently I use some JavaSyntax,as follow:
1)Formatter
import java.util.Formatter;
Formatter f=new Formatter(System.out);
//output a string s,give it 40 char size and flush left
f.format("%-40s",s);
//output a double d,give it 40 char size and save 4 decimal and default flush right
f.format("%-40.4f", d);
2)create a .arff file and output data to file
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
File f = new File("d:/" + "weather" + ".arff");
DataOutputStream out=
new DataOutputStream(
new FileOutputStream(f));
out.writeBytes("@relation weather");
//remove blanks among the string
String s="hello world";
out.writeBytes(s.replaceAll(" ", ""));
3)save 4 decimal
import java.text.DecimalFormat;
DecimalFormat digits=new DecimalFormat("0.0000");
double value=d;
out.writeBytes(digits.format(value));

没有评论:
发表评论