تشارك هذه المقالة أمثلة على كلمة تشغيل Java البسيطة بالنسبة لك للرجوع إليها. المحتوى المحدد كما يلي
package apache.poi ؛ import java.io.bytearrayinputStream ؛ import java.io.bytearrayoutputstream ؛ import java.io java.util.map ؛ استيراد org.apache.poi.hwpf.hwpfdocument ؛ استيراد org.apache.poi.hwpf.usermodel.range ؛ import org.apache.poi.poifs.filesystem.directoryentry ؛ exportDoctest {public static void main (string [] args) {String destFile = "d: //11.doc" ؛ // ## طلب FileCon = new StringBuffer () ؛ FileCon.Append ("Zhang Dapaoman 317258963215223/N" + "2011 09 2013 07 3/N" + "Second Pawn Research Adult/N" + "2013000001 2013 07 08") ؛ filecon.append ("/n/r/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/n/ N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N /N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/ N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N /N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/ N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N /N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/ N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N map=new HashMap<String, String>(); map.put("name", "Zues"); map.put("sex", "male"); map.put("idCard", "200010"); map.put("year1", "2000"); map.put("month1", "07"); map.put("year2", "2008"); map.put("month2", "07"); map.put ("الفجوة" ، // لاحظ موقع مستند Biyezheng_moban.doc ، في هذا المثال ، دليل جذر التطبيق hwpfdocument document = جديد exportDoctest (). استبدال ("biyezheng_moban.doc" ، الخريطة) ؛ bytearrayoutputstream ostream = new bytearrayoutputStream () ؛ حاول {document.write (ostream) ؛ // الإخراج ملفات ملف الإخراج outStream = fileOutputStream جديد (destFile) ؛ Outs.Write (ostream.tobytearray ()) ؛ utt.close () ؛ } catch (ioException e) {E.PrintStackTrace () ؛ }} /** * * param destfile * param filecon * /public void exportdoc (سلسلة destfile ، سلسلة filecon) {try {// doc content bytearrayinputstream bais = new BytearRayInputStream (fileCon.getBytes ()) ؛ poifsfilesystem fs = new poifsfilesystem () ؛ دليل الدليل = fs.getRoot () ؛ directory.createdocument ("WordDocument" ، bais) ؛ FileOutputStream Ostream = جديد fileOutputStream (destFile) ؛ fs.writefilessystem (ostream) ؛ bais.close () ؛ ostream.close () ؛ } catch (ioException e) {E.PrintStackTrace () ؛ }} / ** * اقرأ قالب كلمة واستبدل المتغير * param srcpath * param map * regurn * / public hwpfdocument استبدال (سلسلة srcpath ، map <string ، string> map) {try {// read template template fileputstream fis = new fileputstream (file new (srcpath)) ؛ hwpfdocument doc = new hwpfdocument (fis) ؛ // قراءة كلمة نص محتوى النطاق bodyrange = doc.getRange () ؛ // استبدل محتوى النص لـ (map.entry <string ، string> intern: map.entryset ()) {bodyrange.replacetext ("$ {" + entrate.getKey () + "}" ، intervalue ()) ؛ } مستند الإرجاع ؛ } catch (استثناء e) {E.PrintStackTrace () ؛ العودة لاغية. }}}ما سبق هو كل شيء عن هذا المقال ، آمل أن يكون مفيدًا لتعلم الجميع.