java - The Execution of the following code fails to terminate despite giving the expected output, why? -
the execution of following code used update redirected urls urls present in excel, fails terminate despite giving expected output. program selects excel file in urls checked present updates url url present in excel redirects. can give me reason.
import java.io.file; import java.io.fileinputstream; import java.io.fileoutputstream; import java.io.ioexception; import java.net.url; import java.util.arraylist; import java.util.list; import javax.net.ssl.httpsurlconnection; import javax.swing.jfilechooser; import javax.swing.jframe; import org.apache.poi.ss.usermodel.cell; import org.apache.poi.ss.usermodel.row; import org.apache.poi.xssf.usermodel.xssfsheet; import org.apache.poi.xssf.usermodel.xssfworkbook; public class selenium_sample1 extends jframe { public static void main(string[] args) throws ioexception { string s, sss = null; int rownum = 6; jframe jf = new jframe(); jfilechooser filechooser = new jfilechooser(); filechooser.setcurrentdirectory(new file(system.getproperty("user.home") + "/desktop")); int result = filechooser.showopendialog(jf); if (result == jfilechooser.approve_option) { file selectedfile = filechooser.getselectedfile(); sss = selectedfile.getabsolutepath(); system.out.println("selected file: " + sss); } fileinputstream filei = new fileinputstream(new file(sss)); // create workbook instance holding reference .xlsx file xssfworkbook workbook = new xssfworkbook(filei); // first/desired sheet workbook xssfsheet sheet = workbook.getsheetat(0); cell cell = null; row row = null; int lastr = sheet.getlastrownum(); system.out.println(lastr); list <string> redirectedurl = new arraylist<string>(); (int = 0; <= lastr; i++) { row = sheet.getrow(i); // each row, iterate through columns cell = row.getcell(0); system.out.println(cell.tostring()); url url = new url(cell.tostring()); httpsurlconnection connection = (httpsurlconnection) url.openconnection(); connection.setrequestmethod("get"); connection.setinstancefollowredirects(false); connection.setrequestproperty("user-agent", "mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.11 (khtml, gecko) chrome/23.0.1271.95 safari/537.11"); connection.connect(); int code = connection.getresponsecode(); // e.printstacktrace(); system.out.println(code); s = connection.getheaderfield("location"); if (code / 100 == 3) redirectedurl.add(s); else redirectedurl.add(" "); } (string ss: redirectedurl) { row roww = sheet.createrow(rownum); cell celll = roww.createcell(4); celll.setcellvalue(ss); rownum = rownum + 1; } filei.close(); fileoutputstream fos = new fileoutputstream(new file(sss)); workbook.write(fos); fos.close(); system.out.println("task completed"); } }
Comments
Post a Comment