Reading in a String
Hi,
I'm currently attempting to write my first java console application and have several questions I hope someone out there would be able to answer:
1. How do I read in a String and store it so I could use its value elsewhere?
2. How do I read in a Character and store it so I could use its value elsewhere?
3. How on earth do you use a boolean data type with an if-else loop?
To read a character u say:
char chr=(char)System.in.read();
to read a string u say:
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
or
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
and finally u say
String str=br.readLine();
u may use these values of chr and str as u see fit
vijay
Similar Messages
-
I have a labview sub-VI reading the string being outputted by a pH meter. The meter outputs a 5 line string and labview is only reading up to each lines carriage return, there-by giving me 5 separate strings is there anyway to rectify this and have the 5 line read as one string?
NAS1
St Petersburg FL
Labview 2010Yes, LabVIEW will automatically update. What happens is that the old serial functions still exist in 7.1 and above but the code (the block diagram) has been modified to use VISA functions. Older versions of LabVIEW are fully supported in this manner. The only way you can avoid the automatic update is to have the old serial functions in an llb and your top level VI refer to these. Having any VI that was part of vi.lib in an llb is a very bad idea and the way to fix things is to remove any VIs in the llb that are part of the LabVIEW distribution.
I don't remember how the old serial config worked and what the new version does with the VISA Configure Serial Port. Your program should only have a single serial config and you might just be able to directly replace that with the VISA configure Serial Port. -
How to read date as string (format dd-mm-yyyy) and store it as Date object
Hi. I would like to read from keyboard String with a date and put this value to Date object. How can i do this???
ThanksCheck out java.text.SimpleDateFormat.
Basically
String dateString = readUserInput(); // get the string
SimpleDateFormat myFormat = new SimpleDateFormat("dd-MM-yyyy");
Date myDate = myFormat.parse(dateString); -
Howto read url query string? Help :(
Hi everyone, I am trying to read the query string from within an applet loaded from a URL. I am loading netscape with the following URL
"http://localhost/mypage.html?param1=help"
I am using code:
System.out.println(getDocumentBase().getQuery());
and all I am getting is a null?
This works with appletviewer so could someone tell me what is going on. I have searched the forum but it seems no answer yet exists for this. Perhaps its not possible?
Info:
OS: Redhat Linux 8
java version "1.3.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_02-b02)
Java HotSpot(TM) Client VM (build 1.3.1_02-b02, mixed mode)hi,
can it be that there is a problem with netscape?
it would suggest to try on ie, but you use linux and i dont think theres an ie-version for linux available ;P
i would try it on a different browser like opera or something.
thats my suggestion.
hope this helped
cu Errraddicator -
Difference between VISA READ buffer and string
Hello I am just starting to use the VISA read and write function in labVIEW
anybody knows what are the differene between VISA Read buffer and string? and comparison of VISA Write buffer and string
thanks
Solved!
Go to Solution.Hi Ein,
"read buffer" is the label of the string given by VISARead, "write buffer" is the label of the string expected by VISAWrite!
So there is no difference...
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome -
Reading each incoming string?
How do I read each incoming string?
import java.net.*;
import java.io.*;
public class Mystic_Client{
public static void main(String [] args){
Local l = new Local();
l.Run_Server();
l.Output();
InputThread it = new InputThread();
it.start();
class Local{
static boolean Alive = true;
static Socket server;
static BufferedReader input;
static PrintWriter socket_out;
public void Run_Server(){
try{
server = new Socket("127.0.0.1",27700);
System.out.println("Connection Opened");
}catch(Exception e){
System.out.println(e);
System.exit(0);
public void Shutdown_Server(){
try{
Alive = false;
InputThread it = new InputThread();
input.close();
socket_out.close();
it.socket_in.close();
server.close();
System.exit(0);
}catch(Exception e){
System.exit(0);
public void Output(){
String handle;
String input_message;
try{
input = new BufferedReader(new InputStreamReader(System.in));
socket_out = new PrintWriter(server.getOutputStream(),true);
System.out.print("Handle - ");
handle = input.readLine();
for(;(input_message = input.readLine()) != null;){
if(input_message.equals("~disconnect")){
Shutdown_Server();
socket_out.println(handle + " <> " + input_message);
}catch(Exception e){
System.out.println(e);
Shutdown_Server();
class InputThread extends Thread{
Local l = new Local();
static BufferedReader socket_in;
String socket_in_message;
public void run(){
try{
Socket server = l.server;
socket_in = new BufferedReader(new InputStreamReader(server.getInputStream()));
for(;l.Alive == true;){
}catch(Exception e){
System.out.println(e);
l.Shutdown_Server();
}In the public void run() it suppost to check for new incoming strings to display for my chat program. I started to try something with a for loop, but I'm just not sure yet.
Please Help!
Thanks!Shouldn't this work? It compiles, but it won't actually display incoming messages:
import java.net.*;
import java.io.*;
public class Mystic_Client{
public static void main(String [] args){
Local l = new Local();
l.Run_Server();
l.Output();
InputThread it = new InputThread();
it.start();
class Local{
static boolean Alive = true;
static Socket server;
static BufferedReader input;
static PrintWriter socket_out;
public void Run_Server(){
try{
server = new Socket("127.0.0.1",27700);
System.out.println("Connection Opened");
}catch(Exception e){
System.out.println(e);
System.exit(0);
public void Shutdown_Server(){
try{
Alive = false;
InputThread it = new InputThread();
input.close();
socket_out.close();
it.socket_in.close();
server.close();
System.exit(0);
}catch(Exception e){
System.exit(0);
public void Output(){
String handle;
String input_message;
try{
input = new BufferedReader(new InputStreamReader(System.in));
socket_out = new PrintWriter(server.getOutputStream(),true);
System.out.print("Handle - ");
handle = input.readLine();
for(;(input_message = input.readLine()) != null;){
if(input_message.equals("~disconnect")){
socket_out.println("~disconnect");
Shutdown_Server();
socket_out.println(handle + " <> " + input_message);
}catch(Exception e){
System.out.println(e);
Shutdown_Server();
class InputThread extends Thread{
Local l = new Local();
static BufferedReader socket_in;
static String socket_in_message;
public void run(){
try{
Socket server = l.server;
socket_in = new BufferedReader(new InputStreamReader(server.getInputStream()));
for(;l.Alive == true;){
socket_in_message = socket_in.readLine();
System.out.println(socket_in_message);
}catch(Exception e){
System.out.println(e);
l.Shutdown_Server();
} -
How do I read two dimentional string object in C through JNI
HI,
I am new to JNI and Java as well. I want to read two dimentional string object passed by java to a native method written in C/C++. Say for example I have declared a two dimentional string object as below:
In Java
class InstanceFieldAccess {
private String [][] originalAddress = new String[][13];
private static native String [] accessField(String [][] referenceAddress);
public static void main(String args[]) {
/// Java code to get the string object and pass the string object to native method
new InstanceFieldAccess ().accessField(referenceAddress);
static {
System.loadLibrary("ReadStr");
In C/C++
I want to read the passed two dimentional string array in C/C++ native code and do the further processing and pass the string
back to Java class.
Could anybody tell me how to write the corresponding C/C++ native method.
Thanks in Advance.
Pramod.i got it thanks.
-
How can I read an XML string that's not from an XML file?
I've got a script I'm trying to setup that communicates over a socket to retrieve different directions from a custom built Java program. The Java program listens to requests from the Adobe scripting engine (in my case it's a Photoshop script) on a socket and immediately responds with the next set of directions. These directions are currently in XML format. The issue I'm having is that I can't parse the XML data since it's entered into a new XML object from a string rather than being read from a file. Even without the socket code, you can see the issue by doing the following:
var xml = new XML("<test><data>hey!</data></test>");
alert(xml.test.data);
alert(xml);
The first alert "should" return "hey!" (without quotes, of course), but it doesn't, while the second alert returns what you would expect it to:
<test>
<data>hey!</data>
</test>
It works fine if read from an XML file, but from a string, like shown above, it just presents an empty alert box when attempting to access "xml.test.data". Any ideas on how to fix this issue? Can it be fixed? Has it been fixed in newer versions (I'm currently using CS4)?
Thanks in advance for any help!Duh... found my error... I was attempting to access the data by referencing the created "root" element. Since <test> is the very first element tag, it's setup as the root element, which you don't need to reference. Changing the alert to alert(xml.data); fixed it.
Now I just feel dumb, lol... -
Read the first string in the line, skipping the whitespace ---Possible???
I am parsing through the following file:
* AOCSOnLupda.h
* Created on: 20.07.2010
* Author: perv_na
#ifndef AOCSONLUPDA_H_
#define AOCSONLUPDA_H_
// holds the value of on_lupda
namespace AOCS {
class AOCSOnLupda{
private:
/* public part
public:
#endif /* AOCSONLUPDA_H_ */My main task is to, go inside this file, check if the namespace and class name provided by the user matches the one's inside this file. And then write a boolean initialization (e.g. boolean checked = 1).
The problems I am facing is that, when I read through each line I want to make sure that there is no Block Comment signs or // sign in the beginning of the line. So that I am sure that I am not writing the initialization inside a comment line or something.
My problem is I am not at all being able to read the first word of a line (without the whitespace).
Can someone please tell me how you can skip the first whitespaces in a newly read line, and retrieve the first chars/String? Like in the line:
/* public part
public:there is white space before the start and end of the block comment. And also in front of the word "public:"
How do I get my hands on the start and end of block comment character and also "public:" by skipping the white spaces in front?
Thank you
newbie
Edited by: JFC_newbie on Jul 27, 2010 8:46 AMHi,
thank you for the link ... but I am actually trying to do by myself.
BufferedReader in;
String lineInFile;
try {
in = new BufferedReader(
new FileReader(
"C:/Users/jui/Eclipse/eclipse-java-helios-win32-x86_64/javaWorkspace/FilePathSearchCreateTest/aocsFiles/AOCSOnLupda.h"));// open
while ((lineInFile = in.readLine()) != null) {
if((lineInFile.trim().length())!=0){ //If not a Blank Line then...
* //Read the first non-whitespace char in the read line *
String [] tempLine = lineInFile.split("\\s");
System.out.println(tempLine[0]);
in.close();// safely close the BufferedReader after use
} catch (IOException e) {
System.out.println("There was a problem:" + e);
}But it's not working. I need my code to read the first char/String in a newly read line, by skipping the first whitespaces.
Would really really appreciate some tips. thank you. -
To read a connection string from a notepad
i want to read the DSN-less connection string from a notepad that is from a text file so that if server ip address changes then it will be easy to change the ip address in the notepad rather than changing the code .we are using jsp.
Connection con=DriverManager.getConnection("jdbc:odbc:DRIVER={SQL Server};Database=profile;Server=10.11.144.124;uid=sa;pwd=sa123");
so this connection should be read from the text file
any suggestions
Thanks for ur helpi want to read the DSN-less connection string from a
notepad that is from a text file so that if server ip
address changes then it will be easy to change the ip
address in the notepad rather than changing the code
.we are using jsp.
Connection
con=DriverManager.getConnection("jdbc:odbc:DRIVER={SQL
Server};Database=profile;Server=10.11.144.124;uid=sa;p
wd=sa123");
so this connection should be read from the text file
ny suggestions
Thanks for ur help=> Good way of getting the DSN or any other setting from a text file is create a simple bean(will have get and may have set method too)that will read the data from the text file and use the bean anywhere in your jsp page(As it will also improve the performance of the application)and the bean initilizd once can be reused anywhere in the application. -
How to continously read for a string or word in a file?
Hi
I have been trying for a while now to search for a word that is being written to a file.
I was wondering if anyone can get me over this hump?
What I am doing is reading from the serial port to a file (example file called test), and while this is being done I want to search for the word "passed" or the phrase "test passed"
Once I fine this word or phrase, I can stop the test
I cannot figure out how to search the file, I used the scan file VI and the search/ replace VI etc with no luck!
Your suggestions is appreciatedIt's always best to post your code so others can see the work you've done. Suggestions will be more effective that way.
So your reading from a serial port to a file? What do you mean by this? Are you reading from the serial port and writing the data to a file? It's the file you want to read, isn't it? If I had your code I could answer my own questions
Why don't you just monitor the incoming data stream from the serial port for "passed."
But to read from a file and search for a string, Smercurio is correct. Match Pattern will do what you need (You can use this same function for ASCII serial data as well).
Reese, (former CLAD, future CLD)
Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home -
Barcode reader input to string control
Hi,
I am using a barcode reader that uses keyboard emulation. The barcode types on the computer the same way a keyboard would. When I open notepad and use the barcode reader to read a barcode, the following meesage is typed:
S/N: 17967
Lin: 0.591%
Ph: 1.32deg
In that exact format. However, when I try use the reader in labview with a string control the format changes. The following meassages are printed instead:
S/N: 17967mn: 0.591%m: 1.32deg
S/N: 17967mn: 0.591%mn: 1.32deg
S/N: 17967mnLin: 0.591%mPh: 1.32deg
S/N: 17967mn: 0.591%m:1.32deg
So the format changes. Sometimes the Lin and Ph are printed other times they are not, spacing in the string changes, and in all cases the carriage return is no longer there.
Could you please let me know what might be causing this. Ideally I would like the message to be read in the same format it is in notepad. My code is attached.
Thanks
Attachments:
barcodereader.vi 16 KBIs there a reason you have a timeout event? You are not doing anything in there. So I would remove the timeout (you can just remove the timeout input or set it to -1).
I'm just thinking that if you set the focus while the scanner is doing its thing is causing the issue you are seeing.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
How to read/convert hexidecimal string to an interger
Hello everyone,
This is probably very simple but non of my books show what I need to do. I am running Java 1.4.2 and not ready yet for 1.5.
I wanted to read Property entries containing hexidecimal entries and then convert the hexidecimal entries (which are in String format) into a number either int., long,double or Interger.
Property entry:
address=0x06FE
Property prop = new ....
String addr = prop.getProperty("address");
Interger num = new Interger.parseInt(addr); <---- fails
Would appreciate your help
Regards,
UlisesInteger.parseInt(addr, 16);
//or
Integer.valueOf(addr, 16);
Note that you should call the method by the classname, as it's static. Do n't try to do new Integer as you're doing. -
BareCode reader and insert String into actual selected JTextField
Hi everyone,
I can't invent anything appropriate about my concept. I would like to write a program for BareCode reading. I have working code witch gets a text string from reader which is connected over RS232. But I have to send this String to actual selected JTextField in other java program. I think to use clipboard to overcome this problem but I'm not sure if it's a good solution. Copy this String to clipboard and auto Paste... Any ideas ?
Please help me!
Many thanks for any advices :)Hmm... I missed that bit about having to poke it into
another Java program. In that case I would
look into modifying the other Java program instead of
trying to write a separate program to deal with it.
Otherwise you run into management issues like making
sure the other program is running, and not minimized,
and located at the right place on the screen, and has
the JTextField in question in focus, and so on.In most cases, I would agree. But if his java program is header-less and just responds to the serial events and calls Robot.keyPress() and Robot.keyRelease() he will just be imitating the keyboard, which is exactly what most barcode readers can already do. And this would work in any program that can get keyboard input, no matter what the language was written in.
We are currently doing this with a web-based application. The web page just has a text field and when they scan the barcode it submits the page. Of course the barcode reader we are using just imitates the keyboard, no mucking around converting serial data into keyboard events.
I bet if the OP looks around he could find software that will already convert the barcode RS232 data into keyboard events. -
I need to store a data array and include text that describes what the data is. (using for various configuration files.) Anyway, I would like to be able to save the string as part of the txt file, and somehow read it back, remove the (various length string), and display it in an indicator. All the while, not causing too much problem with the initial data array.
Thanks in advance!!There are several ways to do what you require. A simple method would be to use an ASCII text file. When writing one of those, you just need to basically build a gaint string starting with the description text you want. We like to call that a header. Once you've got the header, make some sort of delimiter like a bunch of "-" or two sets of ( EOL = End of Line = CRLF = \r\n ). After your delimiter, concatenate your array in string form or flatten your array from its native form into a string and tack it on the file (append).
See the (very quick) example attached.
Dan Press
www.primetest.com
Attachments:
fileheader.vi 41 KB
Maybe you are looking for
-
NOOB needs help please....
I am using Dreamweaver to build my website (www.actitudm.com if anyone wants to check it out) and I am having issues with the content loading correctly. It looks like I have the code right, but it isn't finding my CSS or my Images, so the page is all
-
Save project created with trial version in Captivate 5.5 with license
I have a project created with Captivate6 trial version. Now I have a license for Adobe Captivate5.5. The content of my project with Captivate6 will expire when the trial period is over and will not be accessible. I cannot open the .cptx file with Cap
-
Quarter hour appointments and Active Sync
Hello, I want to say sorry if this is a duplicate post but I was unable to find a resolution. I have a user using the current $99 iPhone 3g connected via Active sync to the company Exchange 2003 server. He sent me some screen shots of his Outlook and
-
Automatic Play of Song When Importing Using Double Click
In previous versions of iTunes, I was able to double click a mp3 file on my desktop, have it copied into my iTunes library, and play automatically. Now, in iTunes 8, the file copies but does not play automatically. Is there a way to re-enable this fe
-
Hyperion financial reporting studio hit an unexpected error occurred
Hi everyone, i do not know whether this is the right place to post this query but gave a try. Here is my problem: This is newly setup client PC with financial reporting. When trying to login to the FR, it prompted "*An Unexpected Error Occurred*". Lo