I need to take standard input from a file in IntelliJ IDEA.
$ java BinarySearch tinyW.txt < tinyT.txt
'tinyT.txt' is the file which is to be taken as standard input. 'tinyW.txt' is another file which is passed as a command-line argument to the program.
How can this be achieved through IntelliJ?
PS: I am not running this program from the command-line as the class-path variable hasn't been set, and I am using functions from external libraries.
You need to create a "Run/Debug Configuration" (Menu "Run" -> "Edit Configurations...").
About halfway down in the configuration panel is an entry "Redirect input from" with a checkbox before it. After selecting the checkbox you can select the file "tinyT.txt".
"tinyW.txt" has to be entered into the field "Program arguments"
Related
The Error is shown when I input anything in the output window
As the name implies, output window is only for displaying output. It seems that you're using VSCode Coderunner extension, which by default runs program in output window.
To change it to terminal, simply put :
"code-runner.runInTerminal": true
In your VSCode User Settings (shortcut: Ctrl + ,).
In general, this problem seems to occur in code runner. But when I was Doing settings according to the upper Most Upvoted Answer, I was not able to edit Json File Correctly as It's showing some error. So, If this is the case, You can do this too.
GO TO VS CODE SETTINGS.
IN USER SEARCH BAR, Type CODE RUNNER TERMINAL
Now, Check the option of Run in Terminal. Voila!! Good To Go!
Solution Image
Type the input in the console, not the output window.
you cant input anything in output window.
if you want make any change or edit in output section you should first do debug in console box and then you can make any change you want
Use the shortcut command Shift + Ctrl + X to bring out the extensions side bar,
Now in the search extensions in market place entry input "#installed code runner",
Make sure you have installed code runner extension (If you haven't do that now),
Next right click on the extension and select extension settings,
Scroll down to run in terminal, finally select the check button.
That should do it.
The output window is only for outputs. Use your terminal for input-based code.
To get output in terminal of vscode :
step1:
Click Ctrl+, or open the settings
step2:
search for code runner
step3:
turn on the Run in terminal checkboxscreenshot is included
I know Eclipse has default keybindings (copy, paste, etc), and you can set keybinds for commands they've already decided on (Generate Setter/Getter, etc) but is it possible to set up a custom command?
For example, I can press Shift+F5 and it'll automatically type or paste "System.out.println();" for me.
In Eclipse Preferences, go to Java->Editor->Templates
Click on "new" to create a new template.
In your template, write in the "pattern" textarea the command you want to be pasted.
For example :
throw new IllegalArgumentException("");
And in the "name" textbox, write the word that matches to that command.
Then, in Eclipse, in your Java Editor, write that word + auto-completion. Eclipse will propose you,among others may be, your template.
The sysout command name is that template :
System.out.println(${word_selection}${});${cursor}
How would one go about adding a submenu item to the windows explorer context menu (like for example 7-Zip does) for a Java application?
I am aware of two ways to do it. The fancy way is to write a windows shell extension, which is how powerarchiver, winzip etc do it I believe (this involves running code to determine what the context menu items will be dependent on the file chosen).
The simple way, for simple functionality, is you can add an entry in the registry :
HKEY_CLASSES_ROOT\<file type>\shell\<display text>\command
Where <file type> is the files that this context menu should apply to i.e. *, .mdb, .doc
and
<display text> what you want to show in the context menu.
Then add the default string as a path to the application you want to launch from the context menu, and you can use %1 to refer to the currently selected file i.e. for MS Access I use :
HKEY_CLASSES_ROOT\*\shell\MS Access 2000\command
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "%1"
This then adds a context menu item for any file I select (hence the *), which allows me to launch it in MS Access 2000.
Of course, always back up your registry before hacking it.
Your program could do this during install, or on first run.
You could also package the java program in an installer like NSIS and you could use NSIS script to generate explorer context menu
i am facing problem while compiling a java program i am using command promt to run the program . i have kept the file name and class name both same . also i set the path , i have also set the classpath .
the only reason i can come up with is that the may be the file gets saved with a ".txt" extension inside of a ".java" extensions, as filename.java.txt.
it shows the error
javac : file not found <file name.java>
if anyone have any idea about this please tell me.
If you are using Notepad, or a similar program to save your files, surround the entire file name in quotes in the save bar.
For example, instead of writing
program.java
Select "All Files" instead of "Text files", and then in the save text box, write
"program.java"
How your save file should look:
If this is the case, I would recommend using a text editor that is specifically for coding such as Notepad++ or Sublime Text
If you are on Windows Operating System then give the file Name in double quotes like this
"MyJavaFile.java"
then press Save button , it will save your file with java extension
I am using a few functions in my application which i want to replace with other functions (to make it backward compatible)
My question : is it possible to find & replace some specific text in all java files in a package with some tool, or do i have to do it manually on every java file? I have a LOT of java files in the package.
For eg : i want to replace
getExternalCacheDir()
with something like
Environment.getExternalStorageDirectory + "/Android/data/<package_name>/cache/"
the IDE i'm using is Eclipse Helios. Any solutions?
Use Search - File... in Eclipse, search for getExternalCachDir() in *.java, then right click in the Search view, choose Replace All..., enter the replacement text, and click OK.
In eclipse, Just do
right click on function->Refector->Rename
or
select method + press shift+alt+R
This will change your method name through out the project.