當我打開URL時,我有很多文件,有時會添加新文件。我想想要讀取URL中新增文件的內容。 目前我能夠在給定文件名時讀取文件內容。沒有提供任何文件名,我無法讀取最新的文件。如何獲取最新的文件和讀取內容有任何建議..使用java知道URL中最新上傳的文件名
規則所列的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);
}
在上面的代碼中,給出的網址具有打開文件並讀取內容的文件路徑。我如何從可用文件列表(https://xyz.abc.com/filesPath/)中讀取最新文件的內容。
url路徑https://xyz.abc.com/filesPath/上傳了多個文件。
--EDITED--
下面是HTML響應當與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="[email protected]" 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>
文件名提及的推薦代碼 嘗試是spreadTestReport.xls在上述響應。
你可以訪問文件的列表?如果服務器不提供目錄列表,則可能無法完成。 – Compass
@ Compass-是我可以訪問文件列表。我可以點擊任何文件並打開它。一旦文件被打開,如果我在我的代碼中給出了整個路徑,我也可以閱讀這些內容。 – sss