I am missing something regarding redirection and Stream
Using Scanner, am I able to redirect on the fly? I am familiar with redirection in C. Is redirection in Java similar? Do I have to redirect in the following manner:
java myprogram < mytestfile.txtor can I redirect on the fly with Scanner?
Also, is end of file in Java the same as when I provide Scanner input and hit return?
What I desire to do is allow both console use and redirection. If the user prefers redirection, then my program will use Scanner and StringTokenizer to parse each line of the file, ignoring /n and sending a long concatenated string as input further along. If the user prefers console, then I have a method that will read a file and the program continues.
Edited by: 832844 on Feb 24, 2011 8:29 AM
jverd wrote:
>
If you mean a ? b : c, see [url http://download.oracle.com/javase/tutorial/java/nutsandbolts/op2.html]here and/or google for java ternary operator.
What I would ideally like to do is exactly the following: Allow console input using the keyboard and Scanner or allow redirection into Scanner from a file.That's pretty vague.
This is not a vague question at all. My desire is to allow a user of my program at their leisure to run the program and provide input from the keyboard. The program will obviously, for simplicity sake, use Scanner. Now if the user happens to have multiple input they do not want to type into the console using their keyboard, they can feel free to have the option of redirecting input from a file.
Now this is all to be done using:
Scanner keyboard = new Scanner(System.in)That is it, there are no multiple instances of Scanner. This is the front door of the program and it has the responsibility to accept the following:
* single-line input from the keyboard with a return following each line of input
* multiple lines of input from the keyboard via a cut and paste operation such as from a file
* Redirected input from a file that may have commands spanning multiple lines.
The problem encapsulated clearly for me is this: Right now my front door uses Scanner. It can handle single line input, as in, type something, hit return, and watch the fireworks. however, if I decide to redirect from a file that contains multiple lines of data or cut-n-paste from the file containing multiple lines of data, my program will have a brain fart and see only each line as input. For example:
Ex. 1
Keyboard Input: This is my input (followed by carriage return)
Response from the program: Nice job
Ex. 2
File Input: Line 1
Line 2
Line 3
Response from the program: I don't understand, I have only partial data
I don't understand, I have only partial data
I don't understand, I have only partial data
Ex. 3
Cut-n-Paste: Line 1
Line 2
Line 3
Response from the program: I don't understand, I have only partial data
I don't understand, I have only partial data
I don't understand, I have only partial dataIt is clear I provided valid data in all three examples. The only difference is I chose to split that data across multiple lines where each line is followed by a carriage return. The program had a brain fart and barfed all over my data. This is not what I want to happen.
So then how can I do this?
Edited by: 832844 on Feb 24, 2011 10:37 AM
Similar Messages
-
Am I missing something regarding database queries from BPEL?
Hi,
I'm trying to execute what I would think is a simple query from within a BPEL process against an Oracle 10g database.
I have a root table, meter_reading that has an id, a time, a value, and a foreign key to a meter_reading_type table with a simple id-name-description format.
How do I create a PartnerLink in BPEL that queries for the last reading of a particular type? The SQL is easy. The problem is that with the relationship, I can't find the proper format for a pass-through query so that I can do the subselect AND the select by type (name column).
Also, is it possible with the BPEL PM/OC4J combination to output the queries being generated from Toplink?
I've looked through the toplink docs, but they seem to refer to doing this in Java, not in the toplink_mappings.xml file.
Any help would be appreciated. If I'm missing something obvious, please point it out.
Thanks for your time,
ChrisI am guessing from the examples and from looking around that the only solution to this complexity is stored procs and functions. What happens if you're not allowed to use them? Seems like an awkward part of a product that is owned by Oracle.
C -
I want Photoshop and InDesign- If I buy two "single app" subscriptions it is $40/month but if I buy the single app subscription for InDesign and the Photography package it is $30/month. Am I missing something? Are these different versions of Photoshop?
Hi,
No it's the same Photoshop .Photography program is just a temporary promotion pack with Photoshop and Lightroom and it can end anytime .So you can buy Indesign and photography to have Indesign,Photoshop and Lightroom .
Regards, -
I rented a short film on iTunes but didn't have enough space for the HD version I paid for. I was unable to download it in OR convert it to SD for whatever reason and cannot seem to download my purchase on my desktop iTunes. Am I missing something?
When you purchase an HD movie or show, in most cases the SD copy can be downloaded from your purchases area in iTunes. On the main iTunes Store page, go to Purchases under the Quick Links and then select Movies or TV shows as appropraite. Click the "Not On This Computer" button. Uncheck the "Download HD when available" box and you should then see the SD copies of the movies/shows and be able to download them.
Note that with digital copies from a Blu-Ray or DVD, if it comes with an HD copy, you normally cannot get the SD copy as well and have to purchase it separately if you want it.
Regards. -
I have just tried to connect my Mac book pro to an LG Plasma TV via an iWires Mini DisplayPort to HDMI cable. All I get on my TV is the Mac wallpaper and nothing else. I am missing something really silly, could anyone help please.
Hi there. I also bought an iWires mini Display port to HDMI cable and have an LG LED/LCD TV. I plugged it in to my MB Pro and followed the very small writing that came in the package and got both audio and video going. You need to change the audio settings from within System Preferences on your Mac to select your TV as the audio output.
My concern is the data latency - do you experience a delay between moving your mouse on the MBPro and the TV displaying the movement? It is only a fraction of a second, but certainly enough to be annoying, especially in a cable as expensive as the iWire. -
I've had an iWeb site running for 4 months and I publish a monthly newsletter. Since August I've been unable to republish. The test connection under FTP settings works but I get an error message when I try to upload newsletter. Am I missing something?
Where are you hosting the site a what are you using to upload the site files to the server?
OT -
My ipod touch used to sync on my old Hp laptop but now it's not even recognized as a device but will still charge on my new asus windows laptop. Itunes on my old laptop is missing something and won't work and I've reinstalled itunes on the HP already. Could somebody please help me to get my ipod touch to sync on the Asus laptop please?!
Hello hieunguyen2012,
The following article can help get your iPhone to appear in iTunes on your new laptop.
iOS: Device not recognized in iTunes for Windows
http://support.apple.com/kb/TS1538
Cheers,
Allen -
I cant open my itunes. it said i needed to download the 10.5.2 version to be able to upload the songs to my new ipod (touch) and when i went to do that my itunes wont open at all. me and my mom tried everything. i even went on my brothers account to get at least some songs and his did the same thing even though i didnt download it to the newest version. after i downloaded the lastest version and tried to open my itunes it said it was missing something so i went and downloaded it again. i know that was probably bad to do but i didnt know what else to do. even though i went and did that it keeps saying that im missing something. i dont know what to do to get my itunes to work again and if ill have to redownload all my songs and videos again.
Pleas help.
Thanks much,
SammiiPlug your iPod into your computer, it will begin to sync. Now check to see if the playlists have been added.
If not, go to the songs tab under your iPod when it is connected to iTunes, Unless you have checked "Sync all songs (or something to those words)" you should have an option on what you can put on your iPod. Make sure to check the playlists that you want on your iPod. -
Did I miss something in the fine print? I installed Lion and and come to find out, I can no longer open any Word documents or Excel spreadsheets as they are no longer supported (apparently because they are PowerPC apps). Seriously?!?!?!?!! What are my alternatives?
Hi Mary and Matthew
You might find it helpful to "try before you buy" - there is a 30 day free trial offer for Office for Mac 2011, accessible from M's .com website.
You may be able to use this period to open and resave your old documents in a format that enables you to switch instead to using Apple's iWorks apps moving forward.
I initially intended to do something similar, but ended up buying Office as it provided an easier way (for me, at least) to continue working with years worth of old emails, letters, spreadsheets and other documents (from my PC days) without risking damage to their integrity, formatting, etc. -
Am new to Mac. Downloaded Adobe Photoshop Elements and am trying to open it but they want a redemption code and a serial number. Since I downloaded it I don't have either of those but apparently I am missing something because I can't use it unless I enter that info and I don't know where to find it. Can you please help me figure this out. If I purchased the software I would have the serial number but as I said, I purchased and downloaded. Marianne
Photoshop Elements is not part of the Cloud, I will move this to that forum
Photoshop Elements Forum http://forums.adobe.com/community/photoshop_elements
Redemption Code http://helpx.adobe.com/x-productkb/global/redemption-code-help.html
-and https://forums.adobe.com/thread/1572504
Lost serial # http://helpx.adobe.com/x-productkb/global/find-serial-number.html
Select a topic, then click I STILL NEED HELP to activate Photoshop Elements Online chat
-http://helpx.adobe.com/contact.html?product=photoshop-elements or
http://helpx.adobe.com/photoshop-elements/kb/troubleshoot-installation-photoshop-elements- premiere.html -
After downloading a pdf from a website, how can I view the file in Safari 6.0.4 (just as I can in Safari 5.0.6)? I bet that it's simple, but I've missed something, somewhere, and a solution will be greatly appreciated.
Hello Kirk,
Thank's for your efforts, and I just wish that this was the solution. Unfortunately, it isn't because, after double-clicking on the pdf in the website, it simply "opens" in another Safari window as a black screen - the pdf is there, somewhere, but not visible (either as an icon, or as a document).
When I right-click in the black Safari window, where the file is supposed to be, the only option available to display the file is to "Open file in Internet Explorer" (which is not what I want to do). Other options include saving or printing the pdf, which I don't want until I've confirmed that it's the form that I want. The same options are offered if I right-click on the file icon in the website.
Any other suggestions, please? -
I use an Apple bluetooth keyboard with my iPad. In messages I can't find a way to "send" a message without tapping on Send on the iPad's screen. I've tried every key and key combo that I can think of. Am I missing something?
I already have multiple devices and by far I like my iPad the most over laptops and the iPad. That including checking out my friends MacBook Air.
The difference for me is the touch interface on the screen itself for things that do not require a lot of typing. For me, the iPad is more "magical" than anything else I've used.
Again, I do appreciate your answers but you don't know my situation. Not everything is as it is perceived without knowing me and what I have to go through. -
I updated to lion and now don't have a minimize button in the new emails i am writing. Do i really have to save it as a draft to be able to have multiple emails in progress? Or am I missing something obvious?!
Photoshop Elements is not part of the Cloud, I will move this to that forum
Photoshop Elements Forum http://forums.adobe.com/community/photoshop_elements
Redemption Code http://helpx.adobe.com/x-productkb/global/redemption-code-help.html
-and https://forums.adobe.com/thread/1572504
Lost serial # http://helpx.adobe.com/x-productkb/global/find-serial-number.html
Select a topic, then click I STILL NEED HELP to activate Photoshop Elements Online chat
-http://helpx.adobe.com/contact.html?product=photoshop-elements or
http://helpx.adobe.com/photoshop-elements/kb/troubleshoot-installation-photoshop-elements- premiere.html -
i synched iPhone and Pc but can't locate any of library on IPhone - am I missing something obvious ?
What did you select to sync?
It will only sync what you tell it to sync.
iPhone User Guide (For iOS 4.2 and 4.3 Software) -
I am trying to get photos off of my airport time capsule back up onto my new macbook pro. I followed the above instructions and after I choose the library I want to upgrade and hit continue it wants to open my iPhoto to convert, when I click yes it just gives me the original message and sends me back to this page. Am I missing something?
Is your Time Capsule being used for your TimeMachine back up? Or is it simply being used as an external hard drive?
To use a TimeMachine back up you must first restore it
LN
Maybe you are looking for
-
How come i know the ip of the mail server at run time
i'm developing a mail distribution server that can be used to send and receive the mails. now i would like to know that how come i know the ip of the host to which i want to send the e-mail. e.g. if the request comes in from the user and contains the
-
NEF files only show as thumbnail size in preview window
I am using PSE 8 with Bridge CS4 and camera RAW 5.5 on MAC OS X 10.5.8 I recently upgraded from a D80 to a D300s. when i import RAW files into bridge from the 300s they only show up as thumbnail size in the preview window. It was fine with the D80 a
-
Have a download that will not download how can i identify what it is and how to delete it?
Have Iphone 4 have a file that is "hanging out" that fails when I try to download. What steps do I need to do to find out what the file is; and is it possible to delete? THX
-
What now? I got repair failed "Keys out of order" and "Invalid extent entry"
What now? I tried to verify & then repair disk and I got "repair failed" "Keys out of order" and "Invalid extent entry"
-
I have two concurrent report set's running by the following name. Synchronize Workflow LOCAL table (1) (Report Set) Synchronize Workflow LOCAL tables (Report Set) First one is failing and the log file shows the following error. "The stage registered