Home > Back-end >  Java read the file
Java read the file

Time:03-04

Public static void main (String [] args) {String format="insert into table_a (grp_num, number) values (' text ', '% s'); \ n "; The File dataFile=new File (" D:/test/data. TXT "); The File resultFile=new File (" D:/test/result. SQL "); Try (BufferedReader reader=new BufferedReader (new FileReader dataFile ()); BufferedWriter writer=new BufferedWriter (new FileWriter (resultFile))) {if (! ResultFile. The exists ()) {resultFile. CreateNewFile (); } String tempStr; While ((tempStr=reader. ReadLine ())!=null) {writer. Write (the String. Format (format, tempStr)); } writer. Flush (); } the catch (IOException e) {e.p rintStackTrace (); }
}

CodePudding user response:

refer to the original poster little confused duck reply:
public static void main (String [] args) {String format="insert into table_a (grp_num, number) values (' text ', '% s'); \ n "; The File dataFile=new File (" D:/test/data. TXT "); The File resultFile=new File (" D:/test/result. SQL "); Try (BufferedReader reader=new BufferedReader (new FileReader dataFile ()); BufferedWriter writer=new BufferedWriter (new FileWriter (resultFile))) {if (! ResultFile. The exists ()) {resultFile. CreateNewFile (); } String tempStr; While ((tempStr=reader. ReadLine ())!=null) {writer. Write (the String. Format (format, tempStr)); } writer. Flush (); } the catch (IOException e) {e.p rintStackTrace (); }
}


To learn how to code, what is the problem?

 
Public static void main (String [] args) {
String format="insert into table_a (grp_num, number) values (' text ', '% s'); \ n ";
The File dataFile=new File (" D:/test/data. TXT ");
The File resultFile=new File (" D:/test/result. SQL ");
Try (BufferedReader reader=new BufferedReader (
New FileReader dataFile ());
BufferedWriter writer=new BufferedWriter (
New FileWriter (resultFile))) {
if (! ResultFile. The exists ()) {
ResultFile. CreateNewFile ();
}
String tempStr;
While ((tempStr=reader. ReadLine ())!=null) {
Writer. Write (the String. Format (format, tempStr));
}
Writer. Flush ();
} the catch (IOException e) {
e.printStackTrace();
}
}
  • Related