stringreader

Reading a string with new lines from console java

≡放荡痞女 提交于 2019-12-25 08:03:30
问题 I want to read this string (from console not file) for example: one two three four five six seven eight nine So I want to read it per line and put every line in an array. How can I read it? Because if I use scanner, I can only read one line or one word (nextline or next). what I mean is to read for example : one two trhee \n four five six \n seven eight nine... 回答1: You should do by yourself! There is a similer example: public class ReadString { public static void main (String[] args) { //

Using strfind in Matlab for different diagonal directions in a Matrix

烂漫一生 提交于 2019-12-25 02:24:38
问题 Before anyone asks, this is a repost of an earlier question, but I cannot delete it because it has answers, so I am modifying it so that hopefully Daniel R will answer it! I have a grid of numbers and I want to read a string of numbers with strfind in any of the 8 directions. The non-diagonal ones I have managed to get to work fine, it is the diagonal ones that I have been struggling with (except for downRight which Daniel R helped me with earlier which I am very thankful for)! Here is the

Should I close a StringReader?

南楼画角 提交于 2019-12-17 16:32:30
问题 I use a StringReader to turn a string into something I can upload to an SFTP server (it takes a stream). Is there any point in closing that StringReader afterwards? As far as I can see in the source it just sets the string to null ... I could just do it, but since the close method is marked as throwing an IOException and all I have to wrap it in a try catch and the code just ends up looking a lot more horrible than it perhaps needs to be. 回答1: If you know you're dealing with a StringReader

How do I convert a StringReader to a String?

﹥>﹥吖頭↗ 提交于 2019-12-12 07:13:02
问题 I'm trying to convert my StringReader back to a regular String , as shown: String string = reader.toString(); But when I try to read this string out, like this: System.out.println("string: "+string); All I get is a pointer value, like this: java.io.StringReader@2c552c55 Am I doing something wrong in reading the string back? 回答1: The StringReader 's toString method does not return the StringReader internal buffers. You'll need to read from the StringReader to get this. I recommend using the

Change FileWriter to OutputStreamWriter?

烈酒焚心 提交于 2019-12-12 01:36:58
问题 How do I convert the FileWriter to OutputStreamWriter ? This is the directory that I stored the .java files. src/RX/example.java where RX is the package name. I inserted all the images and text files inside the same directory. Here is my working code with FileWriter. try { StringReader stringReader = new StringReader("Save this Message"); BufferedReader bufferedReader = new BufferedReader(stringReader); FileWriter fileWriter = new FileWriter("src/RX/rxUser.txt"); BufferedWriter bufferedWriter

Ignoring specified encoding when deserializing XML

我的未来我决定 提交于 2019-12-08 18:55:38
问题 I am trying to read some XML received from an external interface over a socket. The problem is that the encoding is specified wrong in the XML-header (it says iso-8859-1, but it is utf-16BE). It is documented that the encoding is utf-16BE, but apparently they forgot to set the correct encoding. To ignore the encoding when I deserialize I use a StringReader like this: private static T DeserializeXmlData<T>(byte[] xmlData) { var xmlString = Encoding.BigEndianUnicode.GetString(xmlData); using

How to string multiple TextReaders together?

谁说胖子不能爱 提交于 2019-11-29 14:08:38
I have 3 TextReaders -- a combination of StreamReaders and StringReaders. Conceptually, the concatenation of them is a single text document. I want to call a method (not under my control) that takes a single TextReader. Is there any built-in or easy way to make a concatenating TextReader from multiple TextReaders? (I could write my own TextReader subclass, but it looks like a fair amount of work. In that case, I'd just write them all out to a temp file and then open it with a single StreamReader.) Is there an easy solution to this that I'm missing? I just threw this together, so it's not super

How to string multiple TextReaders together?

≡放荡痞女 提交于 2019-11-28 08:39:16
问题 I have 3 TextReaders -- a combination of StreamReaders and StringReaders. Conceptually, the concatenation of them is a single text document. I want to call a method (not under my control) that takes a single TextReader. Is there any built-in or easy way to make a concatenating TextReader from multiple TextReaders? (I could write my own TextReader subclass, but it looks like a fair amount of work. In that case, I'd just write them all out to a temp file and then open it with a single