I was trying to do basic input output using FileInputStream and FileOutputStream , but it threw this error
Please dont tell me why i am not using Scanner class for input , i was just trying out FileInputStream class
Ok So This is the code:
You can ignore the ShipPlayer , because that is just a basic ship object i added for no purpose
Please dont tell me why i am not using Scanner class for input , i was just trying out FileInputStream class
Ok So This is the code:
You can ignore the ShipPlayer , because that is just a basic ship object i added for no purpose
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.io.File;
import java.io.FileInputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
public class MyWorld extends World
{
int counter=0;
public MyWorld()
{
super(600, 400, 1);
//Add out object that is of the class ShipPlayer
ShipPlayer shipPlayerObject = new ShipPlayer();
addObject(shipPlayerObject,300,200);
}
public void act(){
if(counter<1){
FileInputStream stdin = new FileInputStream(FileDescriptor.in);
FileOutputStream stdout = new FileOutputStream(FileDescriptor.out);
StringBuilder storeString = new StringBuilder();
int character;
System.out.println("Enter some text");
try{
while((character=stdin.read())>-1){
if(character=='\n'){
break;
}
storeString.append(character);
}
//byte[] bytes = storeString.toString().getBytes();
stdout.write(storeString.toString().getBytes());
stdout.write('\n');
stdout.flush();
stdin.close();
stdout.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
}

