/**
* Read file, return string
*
* @param path
* @return
*/
public static list<string> ReadFile (String path) {
list<string> dataList = new arraylist<string> ();
File File = new file (path);
BufferedReader reader = null;
try {
Read the contents of the file in the behavior unit, read a whole line one at a time;
reader = new BufferedReader (new FileReader (file));
String tempstring = null;
int line = 1;
Read one line at a time until NULL is read to the end of the file
while ((tempstring = Reader.readline ()) = null) {
Show line Numbers
System.out.println ("line" +line+ ":" +tempstring);
Datalist.add (tempstring);
line++;
}
Reader.close ();
} catch (IOException e) {
E.printstacktrace ();
} finally {
if (reader! = null) {
try {
Reader.close ();
} catch (IOException E1) {
}
}
}
return dataList;
}
/**
* Convert data into JSON file
*
* @param path
* @param array
*/
public static void Writejsonfile (String path, Jsonarray array) {
File File = new file (path);
FileOutputStream fout = null;
try {
Fout = new FileOutputStream (file);
for (int j = 0; J < Array.size (); j + +) {
Fout.write (Array.getjsonobject (j). ToString (). GetBytes ());
Fout.write ("\ n". GetBytes ());
}
Fout.close ();
} catch (Exception E1) {
E1.printstacktrace ();
}finally{
if (fout!=null) {
try {
Fout.close ();
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
}
}
public static void Madeozonedatatojsonfile (String ozonedatafilepath, String jsonlistpath) {
J.add (1);
list<string> list = ReadFile (Ozonedatafilepath);
Jsonarray jsonlist = new Jsonarray ();
for (String str:list) {
String a = str;
String concentration= "", estate= "", date= "", time= "";
String arg[] = Str.split ("\\s+");
CONCENTRATION=ARG[0];
DATE=ARG[2];
ESTATE=ARG[1];
TIME=ARG[3];
System.out.println (Arg[0]);
Jsonobject Jo = new Jsonobject ();
Jo.put ("concentration", concentration);
Jo.put ("date", date);
Jo.put ("Time", time);
Jo.put ("Estate", estate);
Jsonlist.add (Jo);
System.out.println (str);
}
Writejsonfile (jsonlistpath,jsonlist);
}
Reads text data by number of rows and returns a string array or JSON array