当前位置: 代码迷 >> J2SE >> java.util.Scanner未到文件结尾,hasNext跟hasNextLine()返回false解决方法
  详细解决方案

java.util.Scanner未到文件结尾,hasNext跟hasNextLine()返回false解决方法

热度:20   发布时间:2016-04-24 00:48:23.0
java.util.Scanner未到文件结尾,hasNext跟hasNextLine()返回false
java.util.Scanner未到文件结尾,hasNext跟hasNextLine()返回false,使用默认分割符。
Java code
import java.io.*;public class Scans{    public static void main(String[] args)throws FileNotFoundException{                        PrintWriter pw=new PrintWriter(new File("ttttt.txt"));        Scanner  sc=new Scanner(new File(Scans.class.getResource("").getPath()+"rt1.txt"));        //sc.useDelimiter("\\r*\\n");                while(sc.hasNext()){            pw.print(sc.nextLine()+"$$$$$$$");            System.out.println(sc.hasNext());            if(sc.hasNext())pw.print("\n");        }        pw.flush();    }}//下面是r1.txt/**Extraction Rules (HTML/Web)Target Code    Type    Page Encoding    Query Method    Login Method    Portal Address    :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0001&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0002&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0004&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0005&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0006&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0007&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0008&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0009&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0010&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0011&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0011&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0012&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0013&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0014&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0015&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0016&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0017&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0018&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0019&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0022&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0023&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0023&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0024&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0025&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0026&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0027&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0029&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0030&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0031&dbcode=CLKM&json=&t=%/~ :/%http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0003&dbcode=CLKM&json=&t=%/~List Regex    :/%(?#title)(?i)href="([^"]+)"[^>]*>[^<>]+</a></p>%/~ :/%(?i)setFrame\('([^']+)'\)%/~ :/%[post](?#post)(?#title)(?#accept)(?i)^(?=[\w\W]*?(?:<form[^>]*action="|<PARENT_URL>:\s*)(?<action>[^"<>\s]*)["<])(?=[\w\W]*?name="drpField"[^>]*VALUE="(?<drpField>[^"]*)"|[\W\w])(?=[\w\W]*?name="__EVENTVALIDATION"[^>]*VALUE="(?<__EVENTVALIDATION>[^"]*)"|[\W\w])(?=[\w\W]*?name="__VIEWSTATE"[^>]*VALUE="(?<__VIEWSTATE>[^"]*)"|[\W\w])[\w\W]*href="javascript:KnsPager.go\((?<__CALLBACKPARAM>\d+),'(?<__CALLBACKID>[^']+)'\)" >Next</a>%/~Data Regex    :/%(?#title)(?i)href="([^"]+)"[^>]*>\s*[^<>]+</a>\s*</td%/~Sublink Regex    Metadata Regex    title:/%(?i)href="[^"]+"[^>]*>\s*([^<>]+)</a>\s*</td[^>]*<%/~ author:/%(?i)\【?Author\s*in\s*Chinese\】?(?:<(?!/p)[^>]*>|\s)*<a[^>]*>([^<>]*?)</a>(\;)(?:(?:<(?!/p)[^>]*>|\s)*<a[^>]*>([^<>]*?)</a>(\;))?(?:(?:<(?!/p)[^>]*>|\s)*<a[^>]*>([^<>]*?)</a>)?(?:(?:<(?!/p)[^>]*>|\s)*<a[^>]*>([^<>]*?)</a>(\;))?(?:(?:<(?!/p)[^>]*>|\s)*<a[^>]*>([^<>]*?)</a>)?%/~ datepublished:/%(?i)Author\s*information[\w\W]+?(\d{4})%/~ Publisher:/%(?i)href="[^"]+"[^>]*>([^<>]+)</a></p>%/~        Result:0    Status:Running    Display top:                            List URL -- http://eng.oversea.cnki.net/law/navi/CLKMissue.aspx?dbcode=CLKM&dbPrefix=CLKT&pykm=GGUDUList URL -- http://eng.oversea.cnki.net/law/navi/CLKMissue.aspx?dbcode=CLKM&dbPrefix=CLKT&pykm=GGZSUList URL -- size = 2start...access : http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0001&dbcode=CLKM&json=&t=List URL -- http://eng.oversea.cnki.net/law/navi/CLKMissue.aspx?dbcode=CLKM&dbPrefix=CLKT&pykm=GANHUList URL -- http://eng.oversea.cnki.net/law/navi/CLKMissue.aspx?dbcode=CLKM&dbPrefix=CLKT&pykm=GAHCCList URL -- size = 2access : http://eng.oversea.cnki.net/law/navi/clkb_ifmlist.aspx?navitype=area&navi=0002&dbcode=CLKM&json=&t=©2009, Serials Solutions All rights reservedloadimg*/
  相关解决方案