8 string from InputStream in Java

There is a stream of serialized C# objects (String fields use standard UTF-8). I'm reading the stream and deserializing it in Java (one object at a time). Java uses MUTF-8 format for the string. DataInputStream.readUTF assumes that format. Is there a way to read just one single "standard" UTF-8 string from input stream?

来自Java中InputStream的8个字符串

有一串序列化的C#对象(字符串字段使用标准的UTF-8)。 我正在读取流并使用Java进行反序列化(一次一个对象)。 Java使用MUTF-8格式作为字符串。 DataInputStream.readUTF采用这种格式。 有没有办法从输入流中读取一个单一的“标准”UTF-8字符串?

Read/convert an InputStream to a String

If you have java.io.InputStream object, how should you process that object and produce a String ? Suppose I have an InputStream that contains text data, and I want to convert this to a String . For example, so I can write the contents of the stream to a log file. What is the easiest way to take the InputStream and convert it to a String ? public String convertStreamToString(InputStream is)

读取/转换InputStream为字符串

如果你有java.io.InputStream对象,你应该如何处理这个对象并产生一个String ? 假设我有一个包含文本数据的InputStream ,并且我想将它转换为一个String 。 例如,我可以将流的内容写入日志文件。 采用InputStream并将其转换为String的最简单方法是什么? public String convertStreamToString(InputStream is) { // ??? } 一个很好的方法是使用Apache commons IOUtils将InputStream复制到StringWriter ...类似于 S

Splitting a line to objects in java

I am reading a file. I need to convert each value to java object. String sCurrentLine; BufferedReader br = null; int pointer = 1; try { br = new BufferedReader(new FileReader("src/main/java/com/ali/trillium/p0f.log")); } catch (FileNotFoundException e) { e.printStackTrace(); } while ((sCurrentLine = br.readLine()) != null) { System.out.println(sCurrentLine); System.out.println("

将一条线分割成java中的对象

我正在阅读一个文件。 我需要将每个值转换为java对象。 String sCurrentLine; BufferedReader br = null; int pointer = 1; try { br = new BufferedReader(new FileReader("src/main/java/com/ali/trillium/p0f.log")); } catch (FileNotFoundException e) { e.printStackTrace(); } while ((sCurrentLine = br.readLine()) != null) { System.out.println(sCurrentLine); System.out.println("--------------

Java Delimiter Issue

I am having trouble with delimiters. My code is as follows: Scanner in=new Scanner(System.in); in.useDelimiter("\D"); int x,y,z; System.out.println("Enter 3 digits: "); x=in.nextInt(); y=in.nextInt(); z=in.nextInt(); System.out.println(x + " " + y + " " + z); in.close(); Pardon my lack of experience with delimiters, but I can only get my program to separate input with 1 character, not two. T

Java分隔符问题

我遇到了分隔符问题。 我的代码如下: Scanner in=new Scanner(System.in); in.useDelimiter("\D"); int x,y,z; System.out.println("Enter 3 digits: "); x=in.nextInt(); y=in.nextInt(); z=in.nextInt(); System.out.println(x + " " + y + " " + z); in.close(); 请原谅我对分隔符的经验不足,但我只能让我的程序将输入与1个字符分开,而不是2个。 该程序必须能够输入如下内容: 1 2 3或1, 2, 3 。 目前它可以处理1

Is calling Scanner methods without using the read content bad?

I recently ran into some trouble with Java's Scanner. When calling methods such as nextInt() , it doesn't consume the newline after pressing Enter. My solution is: package scannerfix; import java.util.Scanner; public class scannerFix { static Scanner input = new Scanner(System.in); public static int takeInt() { int retVal = input.nextInt(); input.next

调用扫描仪方法而不使用读取内容不好?

我最近遇到了Java的Scanner的一些麻烦。 当调用诸如nextInt() ,在按Enter之后它不会消耗newline 。 我的解决方案是: package scannerfix; import java.util.Scanner; public class scannerFix { static Scanner input = new Scanner(System.in); public static int takeInt() { int retVal = input.nextInt(); input.nextLine(); return retVal; } public static void

Scanner line separator not working with intellij IDEA

this is my code: public static void main(String[] args) { System.out.println("Insert number:"); int read = creaScanner().nextInt(); System.out.println("I read "+read); } private static Scanner creaScanner() { Scanner s = new Scanner(System.in); s.useDelimiter(System.getProperty("line.separator")); return s; } When i run it and type an int and hit enter it just takes me

扫描仪行分隔符不适用于intellij IDEA

这是我的代码: public static void main(String[] args) { System.out.println("Insert number:"); int read = creaScanner().nextInt(); System.out.println("I read "+read); } private static Scanner creaScanner() { Scanner s = new Scanner(System.in); s.useDelimiter(System.getProperty("line.separator")); return s; } 当我运行它并键入一个int并点击输入它只需要我到下一行并不显示任

Extracting characters and words from a string

I want to scan an input line character by character and produce Strings based on valid tokens which are “true”, “false”, “^” “&”, “!”, “(”, “)” For example if i was given a string such as String line = true & ! (false ^ true) String line = true & ! (false ^ true) I would have to produce the tokens "true", "&", "!", "(", "false"

从字符串中提取字符和单词

我希望逐个字符地扫描输入行,并根据有效标记“true”, “false”, “^” “&”, “!”, “(”, “)”生成字符串 例如,如果我给了一个字符串,如String line = true & ! (false ^ true) String line = true & ! (false ^ true) 我必须产生令牌"true", "&", "!", "(", "false", "^", "true", ")" 我一直试图使用split()将字符串划分

Java String Split with multiple delimiter using pipe '

I am trying to break a string b = "x+yi" into a two integers x and y. This is my original answer. Here I removed trailing 'i' character with substring method: int Integerpart = (int)(new Integer(b.split("\+")[0])); int Imaginary = (int)(new Integer((b.split("\+")[1]). substring(0, b.split("\+")[1].length() - 1))); But I found that the code below just w

Java字符串使用管道分割多个分隔符'

我试图将一个字符串b =“x + yi”分解为两个整数x和y。 这是我的原始答案。 在这里,我用substring方法删除了尾部'i'字符: int Integerpart = (int)(new Integer(b.split("\+")[0])); int Imaginary = (int)(new Integer((b.split("\+")[1]). substring(0, b.split("\+")[1].length() - 1))); 但是我发现下面的代码是一样的: int x = (int)(new Integer(a.split("\+|i")[0])); int y = (int)

Java: Parse lines from files

I am in need of some ideas. I have a file with some information like this: AAA222BBB% CC333DDDD% EEEE444FF% The '%' sign is like an indicator of "end of line" I would like to read every line, and then parse it to fit a certain format (4 letters, 3 digits and 4 letters again) - So if it looks like the above, it should insert a special sign or whitespace to fill, like this:

Java:解析文件中的行

我需要一些想法。 我有一个这样的信息的文件: AAA222BBB%CC333DDDD%EEEE444FF% '%'符号就像是“行尾”的指示符 我想阅读每一行,然后解析它以适应某种格式(再次使用4个字母,3个数字和4个字母) - 因此,如果看起来像上面那样,它应该插入一个特殊符号或空格来填充,就像这样: AAA-222BBB-%CC - 333DDDD%EEEE444FF - % 我的第一个直接的想法是将每一行读作一个字符串。 然后是一些巨大的if语句,

Using Delimiter not removing special character

The text file contains the following data. I wish to remove the '$' from each row of the text file. I also wish to store the Name,Drink and Cost in variables for future manipulation. However, that can be performed later. I do not understand what is wrong with my code, Here is the Textfile Data: Problem solved using Regex escape pattern. I had to replace the "$" with "

使用分隔符不删除特殊字符

该文本文件包含以下数据。 我希望从文本文件的每一行中删除'$'。 我也希望将变量中的名称,饮料和成本存储起来以供将来操作。 但是,这可以稍后执行。 我不明白我的代码有什么问题,下面是文本文件数据: 问题使用正则表达式转义模式解决。 我必须用“ s * $ s *”替换“$” Rubin$Vodka$55 Alex$Gin$22 Max$Water$FREE 码: File filename = new File("animals2.txt"); try{ Scanner