- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
为了更好地理解我在讲座中听到的内容(关于 Java 输入和输出流),我自己编写了这个小程序:
public static void main (String[] args) throws Exception {
int input;
FileOutputStream fos = new FileOutputStream("test.txt");
// 95 is the underscore-char ( _ ). I use it
// for to finish it reception of input.
while ((input = System.in.read()) != 95) {
fos.write(input);
out.println(input);
}
out.println("- Finished -");
fos.close();
}
它将我刚刚输入的字符的数字表示打印到标准输出。它基本上可以工作,但这是我在 Eclipse 中看到的:
“10”是换行符的十进制 ASCII 表示。
好的。我已经按下回车键以完成迭代。
但是为什么第二个值也会出现呢?
我希望只出现第一个键(实际字符)。
如果能以某种方式解释这个问题,那么我将不胜感激他/她的回答。
@Sanket Makani这是文本文件“text.txt”的相应内容:
2
3
A
a
在 Eclipse 中:
最佳答案
InputStreams 可用于二进制格式,二进制格式不关心过滤换行符。
您需要自己过滤它们,或者使用缓冲阅读器/扫描仪和读取行,然后遍历字符串中的字符。
https://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html#read()
表明它确实一次只读取一个字符,但是在您按下 enter 之前,eclipse 终端可能不会转发输入的数据。
当发生这种情况时,您的循环将运行两次。
扫描仪文档:https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html#nextLine--
关于Java IO : Why does the numerical representation of line feed appear on the console when reading from stdin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44236431/
我有一个 Python 字典 dict。想象一下这个简单的例子。字典: bin1:{apple,apple,cherry,cherry,cherry,banana,banana,avocado} bi
我在Google上搜索了规范表示的含义,然后发现文件太含糊了。谁能提供规范表示的快速解释,以及网站中典型表示攻击的一些典型漏洞是什么? 最佳答案 规范化是您接受输入(例如文件名或字符串)并将其转换为标
本文整理了Java中org.restlet.representation.WriterRepresentation类的一些代码示例,展示了WriterRepresentation类的具体用法。这些代码
这个问题已经有答案了: How to convert number to words in java (32 个回答) 已关闭10 年前。 我有一个列表 Integer从 1 到 100。如果我循环遍
我正在使用 Coin-or Linear Programming图书馆。我想构建一个 ClpPlusMinusOneMatrix .它的构造函数是: ClpPlusMinusOneMatrix (in
免责声明:我完全知道表示日期/时间的最佳方式是 Unix 时间戳或 PHP 的 DateTime 类和 Oracle 的DATE 数据类型。 顺便说一句,我想知道最适合存储时间 数据的数据类型是什么(
我已经编写了我的代码,但就我个人所知,我想知道如何对其进行建模。 我们开始吧:一个用户可以拥有多个配置文件,每个配置文件都与一个且唯一的应用程序相关联。配置文件定义了用户在应用程序中的权限:同一用户可
我想了解 Representable 的含义在 Haskell 中代表。定义 Representable endofunctors over the category of Haskell types
如何构建一个 API,其中相同的数据可以以不同的格式(RESTful 格式)请求。例如。 GET /person/ //get the details of resource 现在,根据客户端(浏
这是这个问题的更具体的变体:Mutate only focus of Store Comonad? ,这样做的好处是不要一次提出多个问题。 是否有兼容 Control.Lens 的镜头它允许我与 co
我一直在为 iOS 开发一个日历应用程序,这让我遇到了很多问题。 我正在使用本地通知进行提醒。存储事件日期、警报日期或其他内容的最佳方式是什么?我的意思是,问题是由时区差异等引起的。我将事件存储在核心
我正在构建一个网络 CMS,用户可以在其中为某些网站元素选择颜色。我想将所有颜色值转换为十六进制以避免任何进一步的格式化麻烦(“rgb(x,y,z)”或命名颜色)。我为此找到了一个很好的 JS 库。
我有像这个例子这样的简单代码: int main() { double i_3 = 4.1; // 8 bytes return 0; } 让我们用 -S 选项编译这个示例: g++ -S -
我正在尝试执行 POST 操作: 我的 Controller 是: @RestController @RequestMapping({"/contacts"}) public class Contac
我需要一个数据表,以便在由一些生成的数据增强的 WPF 数据网格中显示数据。但我还需要将数据从数据库加载到本地 C# 对象,因为表示数据的类会进行很多计算。 那什么更好呢?仅依赖于数据表?或者对象和数
我正在开发一个 Java Spring Boot 应用程序,我使用的是版本 2.1.5 RELEASE。就我而言,我还使用 DozerBeanMapper (5.4.0) 和 Lombok 以防万一这
我正在使用 Postgresql 和 PHP 5.3.x with PDO 来访问数据库。 我有这个 SQL 查询(精简版),需要填写一个 PDO 占位符: INSERT INTO t_article
根据 C11 WG14 draft version N1570 : The header declares several functions useful for classifying and
我正在构建一个网络 CMS,用户可以在其中为某些网站元素选择颜色。我想将所有颜色值转换为十六进制以避免任何进一步的格式化麻烦(“rgb(x,y,z)”或命名颜色)。我为此找到了一个很好的 JS 库。
在golang中,如何将字符串转换为二进制字符串?示例:'CC' 变为 10000111000011 最佳答案 这是一个简单的方法: func stringToBin(s string) (binSt
我是一名优秀的程序员,十分优秀!