Jump to content
  • 0

Readline() Java Problem Doesen't Read The Whole Line.


Question

Posted
			url = new URL(Config.WEB_LINK);
			is = url.openStream(); // throws an IOException
			br = new BufferedReader(new InputStreamReader(is));
			int count = 0;
			while ((line = br.readLine()) != null)
			{
				if (count == 0)
				{
					comanda = line;
				}
				count++;
			}
			System.out.println("DEBUG: Webcheck:" + comanda);

The file is a simple .txt file containing "Still doesen't work how it should."

 

First output: DEBUG: Webcheck:announce Still doesen't work how it s

Second output: DEBUG: Webcheck:announce Still doesen't work how it should.

 

I've made a thread to check every 60 seconds and the first time doesen't read the whole line, but the second time it read it.

Any idea why?

Recommended Posts

  • 0
Posted

U could try with

 

 

try
{
URLConnection conn = new URL(Config.WEB_LINK).openConnection();
conn.addRequestProperty("User-Agent", "Mozilla/4.76");
InputStreamReader isr = new InputStreamReader(conn.getInputStream());
         BufferedReader in = new BufferedReader(isr);
String inputLine;
 
while ((inputLine = in.readLine()) != null)
{
System.out.println("DEBUG: Webcheck:" + inputLine);
}
in.close();
}
catch (Exception e)
{
System.out.println("Something went wrong:" + e);
}

Btw could u post the link of that html ;D

  • 0
Posted (edited)

U could try with

try
{
URLConnection conn = new URL(Config.WEB_LINK).openConnection();
conn.addRequestProperty("User-Agent", "Mozilla/4.76");
InputStreamReader isr = new InputStreamReader(conn.getInputStream());
         BufferedReader in = new BufferedReader(isr);
String inputLine;
 
while ((inputLine = in.readLine()) != null)
{
System.out.println("DEBUG: Webcheck:" + inputLine);
}
in.close();
}
catch (Exception e)
{
System.out.println("Something went wrong:" + e);
}

Btw could u post the link of that html ;D

 

Is a simple txt file, not even html

Edited by TroubleChick
  • 0
Posted (edited)

Whatever but I was lazy to upload one to my ftp to test xD I will, then... q.q

 

P.S: for me it's warking what I posted

 

P.S 2: What you posted is also working for me, with the try() catch() that's missing...

Edited by ^Wyatt
  • 0
Posted (edited)

Whatever but I was lazy to upload one to my ftp to test xD I will, then... q.q

 

P.S: for me it's warking what I posted

I made a different class in eclipse to see if it's working and both ways it's working, BUT when i go in the gameserver first time doesent read all the line and second time it does. I don't get it.

Could be the format of TXT file or anything?!

 <?
if($_POST['Submit']){
$open = fopen("commands.txt","w+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "File updated.<br />"; 
echo "File:<br />";
$file = file("commands.txt");
foreach($file as $text) {
echo $text."<br />";
}
}else{
$file = file("textfile.txt");
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"30\" rows=\"1\">";
foreach($file as $text) {
echo $text;
} 
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?> 

This is the PHP script that edit the file.

Edited by TroubleChick
  • 0
Posted (edited)

I don't think that is about file extension... but u can simply test it...

Btw how did u schedule the check, can u post it here? U could test adding some more seconds for the first check.

Edited by ^Wyatt
  • 0
Posted

ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new checkIt(), 60000, Config.WEB_INTERVAL * 1000);//

 

Everytime i change something at the commands.txt file sometimes it doesen't work from first time.

 

Weird Example: I test the new class with new text everytime and it reads whole. And if i read whole before the new check comes the check is reading whole too.

  • 0
Posted (edited)

But what has to do the php form with your code? I mean, your code is just checking the file, isn't it?

You could give me the link to see if I get your error too  :rage:

Edited by ^Wyatt
  • 0
Posted (edited)

Yes just checking the file and taking the first line. I don't get it why it loose ends of the line first time.

 

LE: Isn't 60 seconds enough?

 

OUTPUT1: DEBUG: Webcheck:announce i dont fucking get it.asda

OUTPUT2: DEBUG: Webcheck:announce i dont fucking get it.asdas

	public static String getContent()
	{
		String comanda = "";
		
		try
		{
			URLConnection conn = new URL(Config.WEB_LINK).openConnection();
			conn.addRequestProperty("User-Agent", "Mozilla/4.76");
			InputStreamReader isr = new InputStreamReader(conn.getInputStream());
			BufferedReader in = new BufferedReader(isr);
			String inputLine;
			int count = 0;
			
			while ((inputLine = in.readLine()) != null)
			{
				if (count == 0)
				{
					System.out.println("DEBUG: Webcheck:" + inputLine);
					comanda = inputLine;
				}
			}
			in.close();
		}
		catch (Exception e)
		{
			System.out.println("Something went wrong:" + e);
		}
		return comanda;
	}
	
Edited by TroubleChick
  • 0
Posted

Ye it should. Try something, debug all lines, not only the first, to make sure that is not related with <br />, if the first check debugs you the line splitted in 2 lines it will be coz <br />, I guess.

  • 0
Posted (edited)

But the file has only 1 line. I'll try to make it html and at the end of line ill put a </br /> to see if its working.

 

LE: Same thing even if it's HTML extension.

 

Not even this way works:

			StringBuilder responseData = new StringBuilder();
			
			while ((inputLine = in.readLine()) != null)
			{
				responseData.append(inputLine);
			}
			System.out.println(responseData.toString());
			comanda = responseData.toString();
Edited by TroubleChick
  • 0
Posted (edited)

I can't help you at all coz I don't understand how do you test it.

Could you explain me what do you do, to be able to do the same as you and get the same problem? ;(

 

Edit: I'm just trying to schedule checks and works fine... it must be problem of your php thing... maybe the first check is trying to access to the file while php is changing it...

Edited by ^Wyatt
  • 0
Posted (edited)

Ok first of all. Im trying to make a script that read a line from a text file from a website.

 

1.If i add the script in gameserver and put to run in Gameserver.java first time it doesen't read the whole line and only few words from it. The next schedule it's reading the whole line.

 

2. I tried to make the script run by itself without putting in gameserver just compiling a java class and it works everytime. i see the output correctly and seeing the whole line.

 

LE: i edit the .txt file manual not with the php script and it works perfectly. Any idea what could php script have?

Edited by TroubleChick
  • 0
Posted

But when you have the script running from the gameserver, what about the .txt file and the php? Is the php chaning it?

Or when does the php act here?

  • 0
Posted

The php script is only to edit the .txt file as i showed you the script a little bit upper

The php act here to. Php is changing the .txt file.

 

 

In theory: I have a file .txt on a server and a .php. The php script is a textarea that edit the txt file. The java script from server reads what is in txt and do what's saying there. Problem is that is not reading the whole line!

  • 0
Posted (edited)

You don't get what am I asking. I wonder WHEN the php script acts and by who.

The php script must be acting when java is trying to check, otherwise it has no sense.

Edited by ^Wyatt
Guest
This topic is now closed to further replies.


  • Posts

    • Hi,   I’m reporting @nuturazvan for attempting to scam me out of 70€.   Last week, he contacted me on Discord saying he was looking for a control panel. I initially offered NimeraCP, but after I told him the price, he said he couldn’t afford it. I then told him I could develop a custom control panel within his budget. After discussing the details, we agreed on the following:   Control / Donate Panel includes: Donate page Account registration page Login page Password reset page Stripe integration Agreed price: 70€ Deal date: December 3, 2025   I finished developing the panel on December 6, 2025, but I have not delivered it yet. The code is complete and currently sitting in a private GitHub repository, waiting for payment. As of December 14, 2025, I still haven’t received any payment. I’ve asked him multiple times when I can expect it, and he keeps making excuses, saying a friend owes him money and that he’s waiting to get paid first.   If you don’t have the money, you shouldn’t be ordering work. I take responsibility for starting the work without upfront payment, but that doesn’t excuse repeatedly delaying payment.   Posting this as a warning to others.  
    • WTB GRACIA FINAL INTERFACE
    • Dear partners! At the moment we are in great need of the following positions: — Snapchat old and new accounts | With snapscores | Geo: Europe/USA | Full access via email/phone number — Reddit old (brute or hacked origin, self-registered) accounts with post and comment karma from 100 to 100,000+ | Full email access included — LinkedIn old accounts with real connections | Geo: Europe/USA | Full email access + active 2FA password — Instagram old accounts (2010–2023) | Full email access (possibly with active 2FA password) — Facebook old accounts (2010–2023) | Full email access (possibly with active 2FA password) | With friends or without friends | Geo: Europe/USA/Asia — Threads accounts | Full email access (possibly with active 2FA password) — TikTok/Facebook/Google ADS Agency advertising accounts — Email accounts: mail.ru, yahoo.com, gazeta.pl, gmx.ch / gmx.de / gmx.net (BUT NOT gmx.com) — Google ADS Manual Farm accounts (verified via email and phone number) | GEO: USA/Europe, mostly USA. — WhatsApp OLD Accounts — Twitter accounts with followers and posts (old accounts) Contact us via the details below. We will be glad to cooperate! We are also ready to consider other partnership and collaboration options. Active links to our projects: Digital goods store (Website): Go to Store Telegram bot: Go to – convenient access to the store via the Telegram messenger. Virtual numbers service: Go to Telegram bot for purchasing Telegram Stars: Go to – fast and profitable purchase of Stars in Telegram. SMM Panel: Go to – promotion of your social media accounts. Contacts and support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
    • Dear partners! At the moment we are in great need of the following positions: — Snapchat old and new accounts | With snapscores | Geo: Europe/USA | Full access via email/phone number — Reddit old (brute or hacked origin, self-registered) accounts with post and comment karma from 100 to 100,000+ | Full email access included — LinkedIn old accounts with real connections | Geo: Europe/USA | Full email access + active 2FA password — Instagram old accounts (2010–2023) | Full email access (possibly with active 2FA password) — Facebook old accounts (2010–2023) | Full email access (possibly with active 2FA password) | With friends or without friends | Geo: Europe/USA/Asia — Threads accounts | Full email access (possibly with active 2FA password) — TikTok/Facebook/Google ADS Agency advertising accounts — Email accounts: mail.ru, yahoo.com, gazeta.pl, gmx.ch / gmx.de / gmx.net (BUT NOT gmx.com) — Google ADS Manual Farm accounts (verified via email and phone number) | GEO: USA/Europe, mostly USA. — WhatsApp OLD Accounts — Twitter accounts with followers and posts (old accounts) Contact us via the details below. We will be glad to cooperate! We are also ready to consider other partnership and collaboration options. Active links to our projects: Digital goods store (Website): Go to Store Telegram bot: Go to – convenient access to the store via the Telegram messenger. Virtual numbers service: Go to Telegram bot for purchasing Telegram Stars: Go to – fast and profitable purchase of Stars in Telegram. SMM Panel: Go to – promotion of your social media accounts. Contacts and support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock