+ 1

Why don't Data Input Stream work in Sololearn??

I know I can use Scanner class to input data as an alternative but I am curious why don't Data Input Stream work here??

13th Jun 2019, 8:11 AM
Saksham Jain
Saksham Jain - avatar
5 ответов
+ 1
DataInputStream() works on sololearn, try this: import java.io.*; class DataInputStreamDemo { public static void main(String args[]) throws IOException { DataOutputStream out = new DataOutputStream( new FileOutputStream("file.dat")); DataInputStream in = new DataInputStream( new FileInputStream( "file.dat")); out.writeInt(123456); int num = in.readInt(); System.out.println("data from input stream: " +num); } }
13th Jun 2019, 9:22 PM
zemiak
+ 1
zemiak I mean it doesn't work for taking input from user as scanner does
14th Jun 2019, 2:43 AM
Saksham Jain
Saksham Jain - avatar
+ 1
Saksham Jain The Scanner is the Java equivalent of taking input from the shell.
29th Jun 2019, 9:47 AM
Loeschzwerg
0
I think you refer to Stdin? This is because we don't have a shell, but a sandboxed environment, which prevents most intrusions through vulnerabilities
13th Jun 2019, 8:18 AM
Loeschzwerg
0
Loeschzwerg What's the difference in working of Scanner and Data Input Stream?
13th Jun 2019, 9:10 AM
Saksham Jain
Saksham Jain - avatar