- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
编辑***:就目前而言,我有一个程序以某种方式陷入无限循环,但是我不确定是什么原因引起的。我的程序从文本文件中读取数据,并从本质上“锯掉”每一行的第一部分数据,直到首次出现','字符,然后读取每个后续字符串(通常情况下以''终止) ),直到下一个','(特殊情况,表示后面的数据也是垃圾)。从那里,它跳到下一行并重复。几周前,我的程序运行良好,但我对此进行了修改,现在它正式被破坏了。在此编辑下方是我遇到的其他一些错误(可能仍需要解决),但此刻,我在某个地方被此循环杀死。我承认我有一个诀窍,就是用嵌套的FOR循环搞砸自己,并使用时髦的迭代器和更新,但是我只是无法破解。这是代码,并带有一些解释。整个代码段仅被放入带有字符串“ synsets”的某个任意类的构造函数中,并在我的main中创建了一个实例。我已评论的其余内容尽可能最佳:
In in = new In(synsets); // Custom input stream class, courtesy
// of Princeton U
Out fout = new Out("log.txt"); // ostream analogue
int linecount=0; // Marker used to keep track of line # in input file
int nouncount=0; // Marker for keeping track of the number of
// "important" data items
// Data comes in the format:
// "junk,important important important,junk
// junk,important,junk
// junk,important important,junk" etc.
{
int i=0;
for ( String str=in.readLine();str!=null;str=in.readLine() )
{
i=0; // reset iterator for a new line
for ( char next=str.charAt(i); next!=',';next=str.charAt(i) )
i++; // This FOR loop cuts out the junk at the start of
// a line
i++; // increment to after first comma
for ( char next=str.charAt(i);next!=',';next=str.charAt(i))
{
for (; next!=',' && next!=' ' ;next=str.charAt(i))
{
i++;
fout.print(next);
// count the "nouns" (important data) on a line
}
nouncount++;
// count the last noun on line, and subsequently fall
// through loops to skip the rest of the junk at the
// current line
fout.print('\n');
}
}
fout.print(nouncount);
in.close();
In in = new In(synsets);
StringBuilder nounData = new StringBuilder();
int linecount=0;
int nouncount=0;
{
String str;
int i=0;
char next='\0';
for ( str=in.readLine();str!=null;str=in.readLine() )
{
linecount++;
}
in.close();
in = new In(synsets);
for ( str=in.readLine();str!=null;str=in.readLine() )
{
i=0;
// The first portion of each line is "trash" until the first comma
for ( next=str.charAt(i) ; next!=',' ; next=str.charAt(++i) ){}
i++;
// This actually reads/processes the data until the next comma, then
// jumps to the next line. "What" i need done is really secondary, I
// just need to figure out what is eating so much space so I can
// trim it
for ( next=str.charAt(i);next!=',';next=str.charAt(i))
for (;next!=','&&next!=' ';next=str.charAt(++i))
nouncount++;
}
}
In in = new In(synsets);
StringBuilder nounData = new StringBuilder();
int linecount=0;
int nouncount=0;
{
int i=0;
for ( String str=in.readLine();str!=null;str=in.readLine() )
{
i=0;
for ( char next=str.charAt(i);next!=',';next=str.charAt(i))
for (;next!=','&&next!=' ';next=str.charAt(++i))
nouncount++;
}
in.close();
in=new In(synsets);
String[] nouns = new String[nouncount];
int j=0;
for ( String str=in.readLine();str!=null;str=in.readLine() )
{
linecount++;
i=0;
for ( char next=str.charAt(i) ; next!=',' ; next=str.charAt(++i) ){}
i++;
for ( char next=str.charAt(i);next!=',';next=str.charAt(i))
{
for (;next!=','&&next!=' ';next=str.charAt(++i))
nounData.append(next);
nouns[j++]=nounData.toString();
nounData.delete(0,nounData.capacity()-1);
}
System.out.println("Current line count is: " + linecount);
}
}
in.close();
System.out.println("line count = "+linecount);
System.out.println("noun count = "+nouncount);
String[] nouns = new String[nouncount];
Current line count is: 1
Current line count is: 2
Current line count is: 3
Current line count is: 4
Current line count is: 5
Current line count is: 6
Current line count is: 7
Current line count is: 8
Current line count is: 9
Current line count is: 10
Current line count is: 11
Current line count is: 12
Current line count is: 13
Current line count is: 14
Current line count is: 15
Current line count is: 16
Current line count is: 17
java.lang.ArrayIndexOutOfBoundsException: 399850
at WordNet.<init>(WordNet.java:39)
at WordNet.main(WordNet.java:212)
nouns[j++]=nounData.toString();
最佳答案
更改所有for
测试条件
next!=','
next != ',' && i < str.length()
for (;next!=','&&next!=' ';next=str.charAt(++i))
for (;next!=','&&next!=' '&&i+1<str.length();next=str.charAt(++i))
String.split(String regex)
String[] words = str.split(",\\s+);
words.length
获得字数统计。要获得行数,请在调用
readLine()
时增加一个计数器,例如
in = new In(synsets);
// for ( str=in.readLine();str!=null;str=in.readLine() )
while ((str = in.readLine()) != null) {
linecount++;
String[] words = str.split(",\\s+);
nouncount += words.length;
}
关于java - 堆重载JVM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29665401/
是否可以复制一个完整的 JVM,并且在故障转移的情况下只需将负载转移到复制的 JVM 上? 如果是,那我们该怎么做呢? 最佳答案 如果您的应用程序是 Web 应用程序,请阅读“集群”和“负载平衡”。大
我读了下面的话,但我想知道它们之间的区别...... JVM 规范、JVM 实现、JVM 运行时 最佳答案 JVM 规范:描述 JVM 应如何运行的文档。 JVM 实现:基于 JVM 规范的 JVM
我目前有四个不同的 java 应用程序,它们由 .bat 文件启动的 jar 运行,这些文件位于 Windows XP Embedded 开始菜单的 starup 文件夹中。我还启动了 Firefox
有人能给我一些关于强制 64 位 jvm 作为 32 位 jvm 运行的想法吗? 我需要为蓝牙连接编写一个 jse 桌面应用程序。为此,我需要实现 Bluecove jar 。它只有 32 位文件。所
我看到过关于这个问题的多条评论——有人说是,有人说不是,许多答案模棱两可。任何人都可以用更简单的术语描述它所在的位置吗?在一篇文章中,我什至看到有人说它与类加载器加载类的类内存共享相同的内存位置 -
我正在寻找所有可能的 jvm 退出代码的完整列表(不是 java System.exit(x))。我使用搜索引擎唯一能找到的是 SIGTERM 退出代码列表:http://journal.thobe.
为了监视任何正常的 Java 进程 JVM,我们可以使用 Attach API。是否有可用于监控 WebSphere JVM 的 API? 最佳答案 您可以使用 PMI(性能监控基础设施)来监控 JV
这个问题在这里已经有了答案: 8年前关闭。 Possible Duplicate: Java - C-Like Fork? 我想知道如何从 JDK fork 子 JVM,甚至有可能这样做吗? 一些框架
JVM 上的哪些图灵完备语言实现不使用 JVM 堆栈作为调用堆栈? (我问是因为我想在同一个线程中实现 Scala 和另一种语言之间的协程。) 最佳答案 闪蝶 SISC(方案代码的第二解释者) 曾经不
我看到here除了 Java 之外,还有很多语言可以在 JVM 上运行。我对在 JVM 中运行的其他语言的整个概念有些困惑。所以: 为 JVM 使用其他语言有什么优势? 为 JVM 编写语言/编译器需
我已经运行了 straced JVM (OpendJDK 11): strace -e trace=mmap java -Xms8192m Main 输出是: mmap(NULL, 8192, PRO
我已经运行了 straced JVM (OpendJDK 11): strace -e trace=mmap java -Xms8192m Main 输出是: mmap(NULL, 8192, PRO
我编写了一个简单的数独求解器。为了粗略测试性能,我使用简单的 System.currentTimeMillis 调用。 我在文本文件中准备了一组初始数独配置。该程序读取该文件并解决每个数独配置。运行测
JVM 被广泛使用:Scala、Groovy、Jython 等。我听说它被描述为“卓越”、“出色”和“严重低估”。为什么? 更具体地说,是什么让 JVM 独一无二?随着所有资金投入 .NET,或者 C
这个问题在这里已经有了答案: 10年前关闭。 Possible Duplicate: Are there any Java VMs which can save their state to a fi
想象一下 6-7 台服务器的设置都完全相同Java 版本“1.6.0_18”OpenJDK 运行时环境 (IcedTea6 1.8) (fedora-36.b18.fc11-i386)OpenJDK
(如有错误请指正) 我了解到,当您通过发出 java 命令来运行 java 程序时, java MyProg 程序将在新的 JVM 上运行。 什么将程序加载到新的 JVM 中?是生成新线程的 JRE
我们有一个使用 JNI 的桌面应用程序偶尔会导致 JVM 崩溃。幸运的是,JVM 会生成一个 hs_err_pidXXXX.log 文件,这对于调试此类错误非常有用。然而,它似乎总是转到当前工作目录,
我在命令提示符下运行一个程序集 jar 文件并得到下面的异常。并导致终止。 Uncaught error from thread [ccp-akka.persistence.dispatchers.d
一、什么是Java虚拟机 虚拟机:指以软件的方式模拟具有完整硬件系统功能、运行在一个完全隔离环境中的完整计算机系统 ,是物理机的软件实现。常用的虚拟机有VMWare,Visual Box,Java
我是一名优秀的程序员,十分优秀!