Opening a file after typing its name from command line?
OK it's been a real long while since I did any Java hacking, how can I do this again?
Here's some source I have from a book.
//ReadTextFile.java
// open the text file
import java.io.File;
import java.io.FileNotFoundException;
import java.lang.IllegalStateException;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class ReadTextFile
private Scanner input;
// enable user to open file
public void openFile()
try
input = new Scanner ( new File ("myfile.txt"));
} //end try
catch ( FileNotFoundException fileNotFoundException )
System.err.println( "Error opening file.");
System.exit(1);
} // end catch
} // end method openFile
// read records from file
public void readRecords()
int callID;
try
while (input.hasNext() )
callID = input.nextInt();
System.out.println(callID);
} // end while
} //end try
catch ( NoSuchElementException elementException )
System.err.println ("File improperly formed.");
input.close();
System.exit(1);
} // end catch
catch ( IllegalStateException stateException )
System.err.println ("Error reading from file." );
System.exit(1);
} // end catch
} // end method readRecords
// close file and terminate app
public void closeFile()
if (input != null )
input.close(); // close file
} // end method closeFile
} // end class ReadTextFile
//ReadTextFileTest.java
public class ReadTextFileTest
public static void main( String args[] )
ReadTextFile application = new ReadTextFile();
application.openFile();
application.readRecords();
application.closeFile();
} // end main
} // end class
So at the command line I wanna do "java ReadTextFileTest openthisfile.txt" or whatever and have it open and read in some stuff from that file instead of hard coding it into the input = new Scanner ( new File ("myfile.txt")); line in the ReadTextFile.java
I'm sure it's pretty simple but like I said, very rusty.
Yeah I figured it out by just passing args[0] into the openFile method. I dunno what was wrong with my brain yesterday, I was typing arg[0] instead of args[0] and not seeing it. One of those days.
Similar Messages
-
How do I prevent adobe reader from opening a file after it's saved from chrome adobe reader?
Whenever I save a file from the chrome adobe reader, it opens automatically in adobe reader which is incredibly annoying. Please help!
Ahh, but that's the design function of any PDF viewer add-on to a browser.
To avoid -- Use the browser feature that saves a file to the local machine.
Then open the file with the appropriate application.
If your machine/device does not support this then you'd want to change to one that supports what you want eh.
Be well... -
Open a PDF to a specific page from command line
I want to open a locally stored PDF file to a specific page from the command line. I have seen examples of accessing web based files using http and the #page= parameter but this does not seem to work for a file stored on my local drive. I want to be able to use VBA from MS Access to control the opening page.
Hi cfwoodbury,
When opening a PDF document from a command shell, you can pass the parameters to the open command using the /A switch with the following syntax:
<Acrobat path> /A "<parameter>=<value>" "<PDF path>"
For example:
Acrobat.exe /A "zoom=1000" "C:\example.pdf"
Regards,
Rave -
Solaris/Linux Reports 6i modify object names from command line
We are running Solaris 2.6 and are converting Reports from 3 to 6i.
We want to change the name of certain objects at the command line, preferably in batch mode.
Any help gratefully received.Looks like the command is being split in some way - the connection to sqlplus is being made before it completes the whole string
It appears to be seeing the @instance_name as a script to execute rather than a db to connect to.
Is the database on the same server as the script?
If so, try setting your environment to the correct databsae, so that you can omit the @instance_name part of the syntax and see if it helps
Also just noticed the failure to open the decrypt script. It would appear uyou are not using a full path name. Have you checked which directroy the scheduled job starts in? You may need to look at running some environment specific scripts first.
Edited by: LindaA on 05-May-2010 07:43 -
Issue with opening .PDF files after recalling from Symantec Enterprise Vault
Good Morning,
I am having issues with opening PDF files that have been recalled from Symantec Enterprise Vault and some of the files are anywhere from 3-4 years old. Some files open, while others return the error: Adobe Reader could not open filename.pdf because it is not a supported file type or might have been damaged. It is inconsistent as to which files it occurs with. I am not ready to believe that I have that many corrupt files out there. I am opening them on a Windows 7 Enterprise SP1 x64 desktop. Adobe 10.1.7. I have already configured the registry setting for bValidateBytesBeforeHeader that I found in another article to no avail.
The files are on a network share, but I also tried copying them to my local desktop and still received the error.
I have seen other posts regarding this error, but do not see a definitive solution and am hoping that in recent days someone has come up with a solution.
Thank You
Brian DoughertyNot supported file type can (but not always) mean the PDF was created with an old enough version of Acrobat, that it isn't comaptible with reader X or XI.
Might have been damaged is pretty cut and dried in its meaning and interpretation.
There's a known issue with Mac OS and Safari Browser "breaking" PDFs as they download, but it's not so common for Windows. Since these are files you already had, it would be even less applicable.
You can try downloading an older version of Reader to check if it's a compatibility issue, but you'd have to uninstall the latest to do it and it'd be a lot of bother if they still don't open. It would also mean they are "broken" and cannot be repaired, that I know of. -
Cannot Open Excel File after exporting from Disco Plus
Hi there,
I got a question from one user having issue with opening Excel file after exporting from Disco Plus.
The report has been using for a while and he is using Excel 2003 version and Discoverer 10g(10.1.2.2), he never got this kind of error before, just recently got error.
After exporting from Disco Plus he saved file on his desktop and when he tries to open the excel it says "Cannot be Accessed, can be corrupted...." but this is not from network drive since he saved file on local desktop or C drive.
Also not for all reports, only this particular report and only specific parameter, for example for parameter 2008 Feb opened successfully, but for2009 Feb he gets this error when trying to open excel.
i tried in excel 2007 also , i dont think this is Excel version error, am not sure.
Also after go live last week (we upgraded database from 9i to 10g) but i am not sure this causes ,since for one parameter working, for other parameter not working.
Actually we should get one window for Macro when we try to open excel, but he is not getting it seems.
Any ideas/thoughts on this would be greatly appreciated.
Thanks for your help
--skatRod,
Thanks for your quick response on this.
Yes, we can export to other formats as well, but actually exporting is working, after saving the file on our local desktop/drive and when we try to open we get this kind messages or we cannot open the file, we should get message window for Macro to enable/disable but for this report we are not getting this either,
Also this happens only for specific parameters,like i mentioned above it works I mean excel file opens for one set of parameters but for some other set of parameters cannot open.
For example :- when we enter FEB 2008 it works, if we enter FEB 2009 it won't open the file.
This is weird
I am still working on this issue, may be better to recreate the report again might be helpful,
Any ideas/comments/thoughts would be great
Thanks
Skat -
Can't open Numbers file after moving it back to Mac from Dropbox
Please help! Can't open Numbers file after moving it back to iMac from Dropbox. Says I need the newer version of Numbers each time I tried to open the file. I am 100% sure that I had the newest version. Spoke to the AppleCare guy and after doing the checks he is also sure that I had the latest version of Numbers and AppleCare can't help. He suggested that maybe i should run it on a file repair program...any suggestion?... please help...
I've read reports of people having trouble when storing Numbers 3 documents on Dropbox. I think it's related to the fact that they're not really "files." They're "packages" that look like files. I had thought that Dropbox had cleared this up with their latest update. You should be on Dropbox version 2.4 or later.
If you have Time Machine you may have some luck going back in time and restoring the document from a previous version.
Storing Numbers documents on iCloud works much better, at least for me, and (unlike Dropbox) iCloud facilitates automatic syncing to other Macs and iOS devices signed into the same Apple ID.
Perhaps you could consider keeping Numbers documents in iCloud instead. iCloud is deeply integrated into the app, and now works well.
SG -
How to open a file with the same name?
Hi, now I practicing making web pages where I put sample codes in one directory and I copy them to edit.
The probrem is, I couldn't open one file while I'm opening another file with the same name.
Is it possible to open a file with the same name in Dreamweaver?That could be a very error prone practice.
May I suggest you take advantage of DW "Snippets" feature instead.
Simply save any blocks of code you will reuse regularly as snippets,
and give each one a descriptive name you like.
Then you can simply place your cursor in code view where you wish the code,
and click insert on the selected item from the snippet panel. -
Malware - Safari users - disable Open"safe" files after downloading
For those not aware there's some malware floating around which goes by the name of MacDefender and other variants.
It's a scam that may show a page suggesting 'virus' infection on the user's machine and/or download an installer file.
Visiting malicious sites or apparently just browsing some Google Images searches will automatically download a zipped file. If the Safari Preference to Open "safe" files after downloading is checked it will unzip and run the installer for the malware.
While installing requires user intervention to click through the installation, the most recent variant will apparently install for a user without needing an administrator password.
Once installed the malware apparently opens unsavoury websites randomly and prompts for credit card details to remove them.
This is unpleasant scareware to steal your credit card info.
Beware.
ACjust for information (in case you haven't seen these yet):
Mac OS X 10.6 Help: What is malware?
How to avoid or remove Mac Defender malware
Mac Virus/Malware Info
Identifying and removing MacDefender trojans -
Cannot open powerpoint file after renaming it.
Cannot open powerpoint file after I renamed it. I keep getting error messages -35 and -108. It says I have unknown access to the file now. What can I do?
As a cross-reference:
Eric Root
Re: Hi! I have a problem with finder
01.03.2014 12:14 (in response to Fexei)
Go to Finder and select your user/home folder. With that Finder window as the front window, either select Finder/View/Show View options or go command - J. When the View options opens, check ’Show Library Folder’. That should make your user library folder visible in your user/home folder. Select Preferences/com.apple.finder.plist. Move the .plist to your desktop.
Re-launch Finder by logging out/in and test. If it works okay, delete the plist from the desktop.
If the same, return the .plist to where you got it from, overwriting the newer ones.
Thanks to leonie for some information contained in this.
You might need to redo the View settings after an update.
Resolved the Problem! Thanks to Eric and Leonie
Felix -
Can't open keynote file after upadating to 1.3.1 !!
I have error opening keynote file after upgrading 1.3.1
strange thing when i updated keynote to 1.3.1 was that the stripe above the screen changed to dark gray to white!
I thought that was new interface but suddenly it has error opening the file.
So i tried to open through webDAV, itunes, but after downloading the 180mb file of keynote, it shows that it has errors for opening files!
this backup keynote file worked just great on 1.3 vers.
http://dl.dropbox.com/u/10521896/NY%20Branch%20Report.key
is the file,
would you plz test the keynote file, which was working just great before bringin heI tried your file on the iPad and Keynote crashed. Then I transferred the file to my Mac, opened it in Keynote on Mac, saved it, and synched back to iPad. Now I can open the file on the iPad -- it takes some time due to all the images. Also, here are some delays between the slides when presenting on the iPad.
BTW: Make sure to use the latest version of Keynote on Mac (5.0.5). -
QT10.1 will not open .wmv file after upgrade to 10.7.4
Hi Qt 10.1 will no longer open .wmv files after upgrading to 10.7.4. I have the latest version of flip for mac. They will opwn in QT7 pro but does anybody have a fix for this problem at all? Thanks in advance.
I'm having the same issue, but do not find a 3ivx codec in the mentioned QT folder. I do, however, have these codecs listed in that folder:
AppleGVAHW.component
ApplePiletVideo.component
AppleProResDecoder.component
AppleVAH264HW.component
QuartzComposer.component
QuickTime3GPP.component
QuickTimeComponents.component
QuickTimeFireWireDV.component
QuickTimeH264.component
QuickTimeIIDCDigitizer.component
QuickTimeImporters.component
QuickTimeMPEG.component
QuickTimeMPEG2.component
QuickTimeMPEG4.component
QuickTimeStreaming.component
QuickTimeUSBVDCDigitizer.component
QuickTimeVR.component
Could ANY of these be causing my wmv files (or my Flip4Mac) to be corrupt and unable to work? I appreciate any insight you may have. -
I can't open pdf files I have down-loaded from Safari
I can't open pdf files I have down-loaded from Safari (6.0 and OSX 10.8) with preview or acrobat. I get a corrupted file message. Anyone have a fix?
From the Safari menu bar, select Safari ▹ Preferences… ▹ Security and uncheck the box labeled Enable plug-ins. Test.
-
Copy file without retyping its name
I`m just starting to use Java (in school) so I need help even with simple things like this: I have to copy file without retyping its name in destination. I`ve tried to use substring method for extracting filename, but it gives me an error "The method substring() is undefined for type Copy". Any help?
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class Copy{
* @param args
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//Entering the path to the file that I want to copy
System.out.println("Enter file path");
String filePath= br.readLine();
//Entering the destination for copied file
System.out.println("Enter destination");
String destination = br.readLine();
FileInputStream fis = new FileInputStream(filePath);
FileOutputStream fos = new FileOutputStream(destination);
int c=0;
while((c=fis.read())!=-1){
fos.write(c);
fis.close();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}cereal_killer wrote:
No. I expected this (String fileName = substring(filePath.lastIndexOf("/")+1, filePath.length());) to workYou didn't provide a string reference on which to execute substring. As in:
String str = "blah blah blah";
String fileName = str.substring(...);
{code}If you just say *substring(start, end)* how is it supposed to know *which* String object to operate on?
Without the someStringReference. preceding it, calling a method--in your case substring--is like calling it on this object, i.e., like this.substring. Your class does not define a substring method, so it's a compile time error to try to call that non-existent method. -
How do I open CS4 files after Upgrading to Cloud? The older files are showing up gray and won't open.
InDesign files are compatible wih all the newer versions. A cs4 file sh
Could you answer a few questions to help us better understand the issue:
If you are trying to open the files by double clicking them, do they give any error??
Have you tried to drag a file into indeisgn, if yes what happends when you do that??
Is there any error message that you get??
Also if you create a new files in InDesign CC does it show up as grey like the cs4 files or do they open fine??
Maybe you are looking for
-
itunes isnt recognising my iphone 4 after i restored my phone and updated it to ios7 on windows, but the computer recognises it...please help ppl..m done with all the recomendations given by apple
-
hi all i think this is a simple (and quite stupid) question, but i don't know ho to solve my problem i work on two computer (windows 2k), one where i have tomcat installed not like a service, the other with tomcat installed like a service. when i wri
-
[solved]Erro while opening emacs and playing mplayer
i install thunderbird and after that i got this error and wallpaper disapper and its now opeing the emacs mplayer: error while loading shared libraries: libjpeg.so.62: cannot open shared object file: No such file or directory whts wrong with it.....
-
AE CS5.5 Trial not showing all export options
I recently downloaded the trial to give it a shot on a project for school I'm working on currently but I've run into an issue. From what I've seen this version is supposed to have full export functions but the only types I'm given on my menus are Ad
-
Japanese character input.
I want to save the Japanese character input from html forms into the Oracle Database using the euc character set. Most of the users use Windows PC, so I guess most of the input would be using s-jis or MS932. Do I need to write the character code conv