-
大小: 620KB文件类型: .zip金币: 1下载: 0 次发布日期: 2022-10-08
- 语言: Java
- 标签: Introduction to Java Programming
资源简介
由 Luiz Arantes Sa编写,并不是随书配套的答案,可以作为参考
代码片段和文件信息
package AppUtils;
import java.io.*;
import java.util.PriorityQueue;
import java.util.Queue;
/**
* Created by Luiz Arantes Sa on 1/29/15.
*/
public class JavaStringRemover {
public static void main(String[] args) {
Queue queue = new PriorityQueue<>(1000);
queue.add(new File(“/Users/Kernel/Desktop/intro-to-java-10th-edition/src“));
int count = 0;
while (!queue.isEmpty()) {
File file = queue.poll();
if (file.isDirectory()) {
File[] listFiles = file.listFiles();
for (File listFile : listFiles) {
queue.add(listFile);
}
} else {
if (!file.getName().matches(“.*.java“))
continue;
try (BufferedReader in = new BufferedReader(new FileReader(file))) {
StringBuilder sb = new StringBuilder(100000);
char[] chars;
while ((in.read(chars = new char[(int)file.length()])) != -1)
sb.append(chars);
in.close();
System.out.println(file.getName());
String s = filterString(sb.toString());
try (BufferedWriter out = new BufferedWriter(new FileWriter(file false))) {
out.write(s.toCharArray());
}
count++;
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static String filterString(String string) {
StringBuilder sb = new StringBuilder(string);
int startIndex = 0;
while ((startIndex = resetToNextState(sb startIndex)) != -1) {
if (states[IN_BLOCK])
startIndex = removeBlockComment(sb startIndex);
else if (states[IN_LINE])
startIndex = removeInlineComment(sb startIndex);
else if (states[IN_STRING])
startIndex = removeStringLiteral(sb startIndex);
else if (states[IN_CHAR])
startIndex = removeCharLiteral(sb startIndex);
}
return sb.toString();
}
private static int removeCharLiteral(StringBuilder sb int startIndex) {
return removeString(sb startIndex tokens[IN_CHAR] “\\“ EXCLUSIVE);
}
private static int removeStringLiteral(StringBuilder sb int startIndex) {
return removeString(sb startIndex tokens[IN_STRING] “\\“ EXCLUSIVE);
}
private static int removeInlineComment(StringBuilder sb int startIndex) {
return removeString(sb startIndex tokens[IN_LINE] ““ KEEP_END);
}
private static int removeBlockComment(StringBuilder sb int startIndex) {
return removeString(sb startIndex tokens[IN_BLOCK] ““ INCLUSIVE);
}
private static final int INCLUSIVE = 0;
private static final int EXCLUSIVE = 1;
private static fin
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-11-09 15:40 intro-to-java-10th-edition-master\
文件 110 2015-11-09 15:40 intro-to-java-10th-edition-master\.gitignore
文件 339 2015-11-09 15:40 intro-to-java-10th-edition-master\README.md
目录 0 2015-11-09 15:40 intro-to-java-10th-edition-master\src\
目录 0 2015-11-09 15:40 intro-to-java-10th-edition-master\src\AppUtils\
文件 6057 2015-11-09 15:40 intro-to-java-10th-edition-master\src\AppUtils\JavaStringRemover.java
目录 0 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_01\
文件 480 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_01\Exercise_01.java
文件 370 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_01\Exercise_02.java
文件 614 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_01\Exercise_03.java
文件 526 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_01\Exercise_04.java
文件 369 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_01\Exercise_05.java
文件 439 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_01\Exercise_06.java
文件 437 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_01\Exercise_07.java
文件 568 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_01\Exercise_08.java
文件 524 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_01\Exercise_09.java
文件 634 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_01\Exercise_10.java
文件 1222 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_01\Exercise_11.java
文件 1176 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_01\Exercise_12.java
文件 839 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_01\Exercise_13.java
目录 0 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_02\
文件 758 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_02\Exercise_01.java
文件 781 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_02\Exercise_02.java
文件 628 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_02\Exercise_03.java
文件 737 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_02\Exercise_04.java
文件 879 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_02\Exersice_05.java
文件 956 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_02\Exersice_06.java
文件 872 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_02\Exersice_07.java
文件 1515 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_02\Exersice_08.java
文件 579 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_02\Exersice_09.java
文件 777 2015-11-09 15:40 intro-to-java-10th-edition-master\src\Chapter_02\Exersice_10.java
............此处省略662个文件信息
- 上一篇:JavaWeb+黑马旅游网
- 下一篇:Java编程思想(第4版)带目录书签.zip
相关资源
- Java编程思想(第4版)带目录书签.z
- JavaWeb+黑马旅游网
- 数据库图书管理系统JAVA代码
- java课程设计汽车修理管理系统
- Java 项目ui设计分析
- 基于mvc的学生档案管理系统
- 网上订餐系统数据库课程设计
- 中国大学MOOC 翁恺 java 兔子与狐狸代码
- java笔试题库-选择题.rar
- 算符优先文法分析器的设计与实现(
- java平台上的实现Diffle-Human的密钥交换
- 酒店预订系统的分析与设计
- java编写的LR语法分析器编译原理实验
- 基于Matlab神经网络工具包编译的jar包
- Java-JDK-11.0.8(Windows & Mac os)
- jdk8_64位安装版
- jdk-8u261-macosx-x64.dmg
- 4本高清中文版Java性能优化经典书籍
- Java语言规范 基于 Java SE 8 高清中文带
-
java解决hive快速导数据到Hba
se代码 - 基于MiniC的语义分析Javacc实现
- java web项目——BBS论坛程序源论坛
- TM00584-java教务管理系统源码.7z
- 算法第4版-谢路云译(Java描述)-完整
- Java安全编码标准-PDF版-有目录
- JAVA加密与解密的艺术第2版
- 基于java/jsp的个人博客系统的设计与实
- 基于jsp/java的新闻发布及管理系统的设
- 贪吃蛇Java源文件代码
- 4448_jsp网页调用摄像头读取二维码
评论
共有 条评论