Browsing 7239 questions and answers with Jon Skeet

Cannot invoke equals(boolean) on the primitive type boolean

I want to check equality of first and last two characters of a string so i have written condition like if (str.length() >= 4 &&...
Jon Skeet
people
quotationmark

I want to check equality of first and last two characters of a string That's not what you're doing though. You're using startsWith and endsWith - you're asking whether a string starts with its own first two characters, and whether it... more 5/12/2015 6:02:40 AM

people

Why aren't my words coming out less than 8 characters?

public String compWord() throws IOException, ClassNotFoundException { // Local constants final int MAX_COUNT = 8; // Local variables BufferedReader reader = new...
Jon Skeet
people
quotationmark

Look at this code: if(word.length() > MAX_COUNT) compWord(); return word; If the word that is picked is longer than your limit, you're calling compWord recursively - but ignoring the return value, and just returning the "too... more 5/11/2015 6:12:29 PM

people

FileStream writing buffer to file

I'm trying to upload a .srt file through an API that takes File as a parameter. The file is stored on the server, and I'm using FileStream and StreamWriter to write to...
Jon Skeet
people
quotationmark

You're currently flushing f, but not s. You're flushing the FileStream, but the StreamWriter wraps that, so it could easily have its own buffer. Don't forget that the FileStream doesn't know anything about the StreamWriter - the... more 5/11/2015 4:55:09 PM

people

Linq:How to make this easy with one line code?

Forget most learnt about linq,now need to review what is it. And how it works.now I need help for this. Please help me .Thank you so much. var everyMonthMoneySum = new...
Jon Skeet
people
quotationmark

It sounds to me like you could do with a dictionary: var results = temp.Where(o => o.IsSign == (short) OrderStateEnum.Success) .GroupBy(o => o.SignMonth) .ToDictionary(g => g.Key, g =>... more 5/11/2015 4:27:52 PM

people

Multi Thread BufferedReader for reading .txt

I'm wanting to read the line of a .txt do the task, and move on to the next line. To make the program quicker, I want to multi-thread so each thread tries a line. The problem...
Jon Skeet
people
quotationmark

I suggest you have one thread doing all the reading, then put the lines into a producer/consumer queue (e.g. a LinkedBlockingQueue) - you can then have multiple threads servicing that queue as consumers. You really don't want multiple... more 5/11/2015 1:24:41 PM

people

Incorrect syntax near '\'

I need to write a program that iterates through a few SQL scripts at a specific path location and executes them. The progress will be incremented on a progress bar, which I still...
Jon Skeet
people
quotationmark

This is the problem: cmd.CommandText = fl.ToString(); You're passing in the filename as the command text, instead of the text itself. You're loading the text here: string scripts = file.OpenText().ReadToEnd(); ... but then not using... more 5/11/2015 9:08:37 AM

people

FileReader over an InputStreamReader

I am going over java.io and some aspects are confusing to me: Is there any perfomance difference between FileReader and InputStreamReader ? Reader fileReader = new...
Jon Skeet
people
quotationmark

I wouldn't focus on the performance. I'd focus on the massive correctness difference between them: FileReader always uses the platform-default encoding, which is almost never a good idea. I believe that's actually slightly more efficient... more 5/11/2015 9:03:05 AM

people

Java Stream BufferedReader file stream

I am using Java 8 Streams to create stream from a csv file. I am using BufferedReader.lines(), I read the docs for BufferedReader.lines(): After execution of the terminal...
Jon Skeet
people
quotationmark

It looks like after reading the file for first time, reader does not get to beginning of the file. No - and I don't know why you would expect it to given the documentation you quoted. Basically, the lines() method doesn't "rewind" the... more 5/11/2015 6:23:47 AM

people

randomAccessFile.readLine() returns null after many uses even though not reaching EOF?

I have a file with 10K lines. I read it in chunks of 200 lines. I have a problem that after 5600 lines (chunk 28), randomAccessFile.readLine() returns null. however, if i start...
Jon Skeet
people
quotationmark

Each time you call getNextRequestsChunkStartingChunkId you're skipping the specified number of chunks, without "rewinding" the RandomAccessFile to the start. So for example, if you... more 5/11/2015 5:45:38 AM

people

C# preprocessor differentiate between operating systems

Is it possible to differentiate between operating systems in C# using preprocessor? like : #if OS_WINDOWS //windows methods #elif OS_MAC //mac methods #elif OS_LINUX //linux...
Jon Skeet
people
quotationmark

No - think about it, the compiler runs once, but the same binary output can be used on multiple machines. Now you can specify any symbols you want when you compile - so you could easily compile three different times and pass in different... more 5/10/2015 4:34:50 PM

people