-3

Is it possible to find instances of // in a line read from a file into a byte array and then "snip" from // to the end of the line out? I'm trying

FileInputStream fis = new FileInputStream(file);
byte[] buffer = new byte[8 * 1024];
int read;

while ((read = fis.read(buffer)) != -1) 
{
    for (int i = 0; i < read; i++) 
    {
        if (buffer[i] == '//')
        {
            buffer = buffer[0:i];
        }
    }
}

but I'm getting Invalid character constant at if (buffer[i] == '//') on the '//' part. Am I doing something wrong, or is this just not possible?

mjswartz
  • 715
  • 1
  • 6
  • 19

2 Answers2

1

Old-school solution

for (int i = 0; i < read-1; i++) 
    {
        (if (buffer[i] == '/') && (buffer[i+1]== '/'))
        {
            buffer = buffer[0:i];
        }
    }
0

' and ' denote one character. Since // are two characters this does not work. One has to differentiate between a character and a string. Thus you have to individually check both positions in the byte array to confirm there are two successive /s.

qwertz
  • 14,614
  • 10
  • 34
  • 46
  • Damn, there are some funny downvoters around. Can you please explain, so I can improve the answer? – qwertz Dec 22 '15 at 17:28