Jump to content

How to close this BufferedReader?

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Deco

Deco

    Newbie

  • Members
  • PipPip
  • 28 posts
private String handleRequest(Socket client)

	{

		try

		{

			BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));

			return in.readLine();

		}

If I close the reader before returning the string I can no longer read from the stream.
Trying to close the stream after the return statement appears impossible.

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
try

		{

			BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));

			String value in.readLine();

                        in.close();

                        return value;

		}


#3
Deco

Deco

    Newbie

  • Members
  • PipPip
  • 28 posts
lol how did I not think of that.

Thanks :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users