When i hit the URL, i have many files and new file is added sometimes. I want to read the content of newly added file in the URL. Currently i can able to read the file content when given the file name. I could not able to read the latest file without giving any filename. Any suggestions on how to get the latest file and read the content..
Code to read the content from a file when given the filename in the URL:
URL url = new URL("https://xyz.abc.com/filesPath/myFile.pptx");
HttpsURLConnection connection = ((HttpsURLConnection) url.openConnection());
InputStream input;
input = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String msg = null;
while ((msg = reader.readLine()) != null) {
System.out.println(msg);
}
In the above code, the url given has the file path which opens the file and read the content. How can i read the content of the latest file from the available files list(https://xyz.abc.com/filesPath/).
The url path https://xyz.abc.com/filesPath/ has multiple files uploaded.
--EDITED--
Below is the html response when tried with the suggested code mentioned in How to get list of files/directories of an directory url in java?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">
<html dir="ltr" class="ms-isBot" lang="en-US">
<head>
<meta name="GENERATOR" content="AllAccess" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=10" />
<meta http-equiv="Expires" content="0" />
<!-- === Page Title loaded from page or page layout ==================================================================== -->
<title>
Raw Data - All Documents
</title>
<!-- === Favicon / Windows Tile ==================================================================== -->
<link rel="shortcut icon" href="/_layouts/15/xxinfo.icon" id="favicon" />
<script type="text/javascript".....>
//..script tags
<body>
...
<tr class="ms-alternating ms-itmhover" iid="39,1428,0">
<td class="ms-vb-itmcbx ms-vb-firstCell"><input type="checkbox" class="s4-itm-cbx" /></td>
<td class="ms-vb-icon"><img border="0" alt="spreadTestReport.xls" title="spreadTestReport.xls" src="/_layouts/15/images/icxls.png?rev=23" /></td>
<td height="100%" onmouseover="OnChildItem(this)" class="ms-vb-title">
<div class="ms-vb itx" onmouseover="OnItem(this)" ctxname="ctx39" id="1428" field="LinkFilename" perm="0x1b03c4312ef" eventtype="">
<a onfocus="OnLink(this)" href="/MyDocuments/Report/spreadTestReport.xls" onmousedown="return VerifyHref(this,event,'1','SharePoint.OpenDocuments','1https://my20infosw.share.gm.com/_layouts/15/WopiFrame.aspx?sourcedoc=/Shared%20Documents/08.Test%20Report/MY20%20Test%20Reports/Sanity/Raw%20Data/spreadTestReport.xls&action=default')" onclick="return DispEx(this,event,'TRUE','FALSE','{$thisNode/@File_x0020_Type.url}','{$thisNode/@File_x0020_Type.progid}','{$XmlDefinition/List/@DefaultItemOpen}','{$thisNode/@HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon}','{$thisNode/@HTML_x0020_File_x0020_Type}','{$thisNode/@serverurl.progid}','{$thisNode/@CheckoutUser.id}','{$Userid}','{$XmlDefinition/List/@ForceCheckout}','{$thisNode/@IsCheckedoutToLocal}','{$thisNode/@PermMask}')">spreadTestReport</a>
</div>
<div class="s4-ctx" onmouseover="OnChildItem(this.parentNode); return false;">
<span> </span>
<a onfocus="OnChildItem(this.parentNode.parentNode); return false;" onclick="PopMenuFromChevron(event); return false;" href="javascript:;" title="Open Menu"></a>
<span> </span>
</div></td>
<td class="ms-vb2">
<nobr>
7/17/2016 10:52 PM
</nobr></td>
<td class="ms-vb-user"><span class="ms-noWrap"><span class="ms-imnSpan"><a href="#" onclick="IMNImageOnClick(event);return false;" class="ms-imnlink ms-spimn-presenceLink"><span class="ms-spimn-presenceWrapper ms-imnImg ms-spimn-imgSize-10x10"><img name="imnmark" class="ms-spimn-img ms-spimn-presence-disconnected-10x10x32" title="" showofflinepawn="1" src="/_layouts/15/images/spimn.png?rev=23" alt="No presence information" sip="rawaa.kashat@gm.com" id="imn_108985,type=sip" /></span></a></span><span class="ms-noWrap ms-imnSpan"><a href="#" onclick="IMNImageOnClick(event);return false;" class="ms-imnlink" tabindex="-1"><img name="imnmark" class="ms-hide" title="" showofflinepawn="1" src="/_layouts/15/images/blank.gif?rev=23" alt="" id="imn" /></a><a class="ms-subtleLink" onclick="GoToLinkOrDialogNewWindow(this);return false;" href="/_layouts/15/userdisp.aspx?ID=113">Spread</a></span></span></td>
</tr>
Filename is spreadTestReport.xls in the above mentioned response.