Results 1 to 9 of 9
Thread: How to get input from Console
- 05-20-2007, 11:23 AM #1
Member
- Join Date
- May 2007
- Posts
- 6
- Rep Power
- 0
- 05-20-2007, 11:28 AM #2levent Guest
You can use a BufferedReader to read a line from the "standard" input stream as follows:
Alternatively, if you are using Java 6 or above, you can use Console class as follows:Java Code:BufferedReader reader = new BufferedReader(System.in); String input = reader.readLine();
Java Code:Console console = System.console(); String username = console.readLine("User: ");
- 05-20-2007, 11:32 AM #3
Member
- Join Date
- May 2007
- Posts
- 6
- Rep Power
- 0
Thanks Levent!
- 12-09-2009, 12:55 PM #4
Member
- Join Date
- Dec 2009
- Location
- AddisAbaba
- Posts
- 10
- Rep Power
- 0
Hey guys i was trying to send file to a server from a client and the file will be sent but a serious of small rectangles which are equal to the array length i initialized are also displayed with the file i sent in the server side; what code should i use to avoid this, please can somebody help me out.
this are the code i used
Client side
public void sendFile(){
try{
bis = new BufferedInputStream(new FileInputStream(jFileChooser1.getSelectedFile()));
bos = new BufferedOutputStream(client.getOutputStream( ));
byteArray = new byte[(int)jFileChooser1.getSelectedFile().length()];
bis.read(byteArray,0, byteArray.length);
bos.write(byteArray,0, byteArray.length);
bis.close();
bos.close();
}
Server side
public void receiveFile(){
try{
byte receivedData[] = new byte[40];
bis = new BufferedInputStream(socket.getInputStream());
bis.read(receivedData);
String st=new String (receivedData,0,receivedData.length);
System.out.println(st);
bos = new BufferedOutputStream(new FileOutputStream("belete.txt"));
bos.write(receivedData);
bis.close();
bos.close();
}
- 12-09-2009, 01:51 PM #5
And how does that relate to getting input from the console? Why do you hijack a dead thread?
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 12-09-2009, 02:03 PM #6
Member
- Join Date
- Dec 2009
- Location
- AddisAbaba
- Posts
- 10
- Rep Power
- 0
it is not about getting input from console its just the file transfer system, please help me out i really need it
- 12-09-2009, 03:31 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 08-13-2010, 09:14 PM #8
Member
- Join Date
- Aug 2010
- Posts
- 1
- Rep Power
- 0
deleted by mod
Last edited by Fubarable; 08-13-2010 at 09:32 PM. Reason: deleted by mod
-
amharic: Please start a new thread for your question rather than hijack an old one. I'm locking this thread.
Similar Threads
-
How to read input from console
By Java Tip in forum java.ioReplies: 0Last Post: 04-16-2008, 10:57 PM -
How to read input from the console
By Java Tip in forum java.ioReplies: 0Last Post: 04-06-2008, 07:41 PM -
Console doesn't appear!
By PeteMarsh in forum New To JavaReplies: 2Last Post: 12-17-2007, 05:41 PM -
Taking input from console
By Java Tip in forum Java TipReplies: 0Last Post: 11-05-2007, 04:47 PM -
how to take input and verify input in Java programs
By bilal_ali_java in forum Advanced JavaReplies: 0Last Post: 07-21-2007, 08:46 AM


LinkBack URL
About LinkBacks


Bookmarks