| |

VerySource

 Forgot password?
 Register
Search
View: 1466|Reply: 12

Java uses UTF-16 encoding under Linux and crashes after exhausting system resources?

[Copy link]

1

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-22 21:30:01
| Show all posts |Read mode
It is just a very simple example, but it causes the system to run out of resources and cannot run. I compiled with Eclipse. If I stop it during the operation, will it be ok? The operating environment used under the virtual machine is not JDK
Please help, how to solve this problem, thank you, the following is the code posted:

public class test {
public static void main (String args []) throws Exception {
byte b [] = new byte [2];
b [0] = 3;
b [1] =-33;
System.out.println ("string:" + new String (b, "UTF-16"));
}
}
Reply

Use magic Report

0

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-5-4 18:00:02
| Show all posts
public static void main (String [] args) {
// TODO Auto-generated method stub
byte b [] = new byte [2];
b [0] = 3;
b [1] =-33;
try {
System.out.println ("string:" + new String (b, "UTF-16"));
}
catch (Exception e)
{
e.printStackTrace ();
}

}
Reply

Use magic Report

0

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-5-4 18:30:01
| Show all posts
Output:
string :?
Reply

Use magic Report

1

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-5-5 15:00:01
| Show all posts
As long as it can output, there is no big problem, mainly because Linux will cause the system resources to be exhausted, and then become a crash
Reply

Use magic Report

0

Threads

18

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-5-5 15:15:01
| Show all posts
It's too hard to say
There is no problem with your code, as a matter of course there will be no resource exhaustion

Is this always the case? How do you know that resources are exhausted?
Reply

Use magic Report

0

Threads

18

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-5-5 20:45:01
| Show all posts
You remove the print, or replace it with
String str = new String (b, "UTF-8");
System.out.println ("length:" + str.length ());
Look at
Reply

Use magic Report

0

Threads

18

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-5-6 06:15:02
| Show all posts
byte b [] = new byte [2]; ???
Reply

Use magic Report

0

Threads

13

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-5-6 15:00:01
| Show all posts
Is there such a situation under win? I am also linux, but the standard encoding under linux is utf-8
Reply

Use magic Report

1

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-5-7 01:00:02
| Show all posts
Using UTF-8 will not cause an error. The system is exhausted because the system is dead at all, and the mouse is difficult to move. Every time, but there is no problem with another compiler
Reply

Use magic Report

1

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-5-7 02:30:01
| Show all posts
Reply tozt103b, this sentence defines byte b [] = new byte [2];
Any questions?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list