I'd like my program to find location from which it was run, i.e. program uses txt file and I'd like it to look for this txt file in the same directory as jar file.  I am aware of the existence of Path class, but I don't have a clue how to use it in this situation. For the time being I'm using a fixed path, but it's not good enough.  package readsqlfromfile; import java.io.*; import java.util.Scanner;   public class ReadSqlFromFile {  static File file = new File ("C:\\sql\\sql.txt");  public static void main(String[] args) throws FileNotFoundException  {       Scanner input =new Scanner(file);      String linia = new String ("");  while (input.hasNextLine()) {     linia = input.nextLine();     if (linia.length()&gt;4) {     if (linia.substring(0, 4).equals("sql:")) {        //some database logic here    }    }        }  } }
I've recently searched how I could get the application's directory in Java. I've finally found the answer but I've needed surprisingly long because searching for such a generic term isn't easy. I think it would be a good idea to compile a list of how to achieve this in multiple languages.  Feel free to up/downvote if you (don't) like the idea and please contribute if you like it.  Clarification:  There's a fine distinction between the directory that contains the executable file and the current working directory (given by pwd under Unix). I was originally interested in the former but feel free to post methods for determining the latter as well (clarifying which one you mean).
Combinatorial expression for all ternary strings that don't have consecutive 1's and 2's for any ring $A$ the matrix ring $M_n(A)$ is simple if and only if $A$ is simple Let integer $n\geq 1$. I have obtained that for any field $k$, the matrix ring $M_n(k)$ is simple, i.e., $M_n(k)$ contains no nonzero proper two sided ideals. Now I want to prove that: for any ring $A$ (not necessarily commutative), the matrix ring $M_n(A)$ is simple if and only if $A$ is simple.   How to prove? Question about Riemann integral and total variation Why does a 'sudo -i' login shell break a here-doc command string argument? In the sequence of five commands below, all depend on single-quotes to hand off possible variable substitution to the called bash shell rather than the calling shell. The calling user is xx, but the called shell will be run as user yy. The first command substitutes $HOME with the calling shell's value because the called shell is not a login shell. The second command substitutes the value of $HOME loaded by a login shell, so it is the value belonging to user yy. The third command does not rely on a $HOME value and creates a file in the guessed home directory of user yy.  Why does the fourth command fail? The intention is that it writes the same file, but relying on the $HOME variable belonging to user yy to ensure it actually does end up in her home directory. I don't understand why a login shell breaks the behaviour of a here-doc command passed in as a static single-quoted string. The failure of the fifth command verifies that this problem is not about variable substitution.  xx@host ~ $ sudo -u yy bash -c 'echo HOME=$HOME' HOME=/home/xx xx@host ~ $ sudo -iu yy bash -c 'echo HOME=$HOME' HOME=/home/yy xx@host ~ $ sudo -u yy bash -c 'cat &gt; /home/yy/test.sh &lt;&lt; "EOF" &gt; script-content &gt; EOF &gt; ' xx@host ~ $ sudo -iu yy bash -c 'cat &gt; $HOME/test.sh &lt;&lt; "EOF" &gt; script-content &gt; EOF &gt; ' bash: warning: here-document at line 0 delimited by end-of-file (wanted `EOFscript-contentEOF') xx@host ~ $ sudo -iu yy bash -c 'cat &gt; /home/yy/test.sh &lt;&lt; "EOF" &gt; script-content &gt; EOF &gt; ' bash: warning: here-document at line 0 delimited by end-of-file (wanted `EOFscript-contentEOF')   These commands were issued on a Linux Mint 18.3 Cinnamon 64-bit system, which is based on Ubuntu 16.04 (Xenial Xerus).  Update: The here-doc aspect is just clouding the issue. Here's a simplification of the problem:  $ sudo bash -c 'echo 1 &gt; echo 2' 1 2 $ sudo -i bash -c 'echo 1 &gt; echo 2' 1echo 2   Why does the first of those two commands preserve the linebreak and the second does not? sudo is common to both commands, yet seems to be escaping/filtering/interpolating differently depending on nothing but the "-i" option. Changing left margin in itemize environment of beamer class I can't figure out how to line up the symbols of an itemize environment in beamer with the left part of the main text. In other words, I would like to supress the left margin in beamer itemize lists.  It would be nice if the solution worked with any itemize label defined with  \setbeamertemplate{itemize item}[]   In order to make myself clearer, what beamer produces by default is something like:  Main text. Main text. Main text...    * Item 1    * Item 2    * Item 3    ....   and the desired result is   Main text. Main text. Main text... * Item 1 * Item 2 * Item 3 .... Cannot set up multiple desktops (workspaces) I usually compress my tex PDFs with ghostscript:  pdflatex -shell-escape file.tex  gs -sDEVICE=pdfwrite        \    -dCompatibilityLevel=1.4   \    -dPDFSETTINGS=/prepress      \    -dNOPAUSE -dQUIET -dBATCH      \    -sOutputFile=file_compressed.pdf \     file.pdf   Normally that works well, but if I have relative links to local files, the links don't work afterwards.  Minimal example:  \documentclass{beamer} \usepackage{hyperref}  \begin{document}     \begin{frame}         \href{run:./audio.mp3}{test}     \end{frame} \end{document}   The link works in file.pdf but not in file_compressed.pdf. Is there any pdflatex or ghostscript setting that retains the link in the compressed version?  I use Acrobate Reader 10.1.14 for viewing, Ghostscript 9.10 and pdfTeX 3.14159265-2.6-1.40.15 (TeX Live 2014) on OS X 10.9.5.    Update: The breakage of hyperlinks had nothing to do with compressing the PDFs. The breakage happened for all re-processing of PDFs containing hyperlinks in its input PDF. How to export data with tab delimiters using Apex Data Loader? The internet vaguely says that this is possible. I need this feature to export translation values from a custom object and then import this back into Salesforce using translation workbench. Translation workbench accepts:   Field delimiter: Tab Character delimiter: None   How can we achieve a tab delimited data export from a custom object using Apex Data Loader? "Available jobs to/for them" First of all, English is not my first language. I have a question, maybe a basic one, about this phrase:     The situation highlights the mismatch between some areas of training and available jobs to/for them.   Should it be "available jobs to them" or "available jobs for them"?  Sorry if the question is really basic. UITableViewCell content overlaps delete button when in editing mode in iOS7 One single command to update everything in Ubuntu? Have we managed to make a perfect vacuum? Have we managed to make a device without any atom inside it on earth? I was reading about vacuum , and I found in the examples part  that even on the best man made vacuum devices, there are still millions of "molecules per $cm^3$". So my other question here is, what are these molecules and what is the mass of them? Show "Insufficient Privileges" directly when clicking 'Edit' (override), not on 'Save' If a user clicks 'Edit' on an opportunity which he isn't allowed to edit, the "Insufficient Privileges" page directly appears. This is good. If a user clicks 'Edit' on a custom object (which has an edit override that points to a visualforce page), he first sees the form without problems, and the "Insufficient Privileges" page only appears when he tries to save it. This behaviour is misleading for the users, because they think they can manipulate the data and put effort into it, and only afterwards they realize that this wasn't possible after all.  An idea was to check at page load if the user has edit permissions and otherwise redirect him to the "Insufficient Privileges" page.  Might there be another way? Thanks! Why do you need explicitly have the "self" argument in a Python method? I can't open google-related sites I'm  getting timeout errors on google-related sites. If I try to open google.com, gmail.com, etc, it will keep displaying the "waiting reply" on the browser bottom, and the page won't open. If I am browsing another site that includes, say, www.google-analytics.com, ajax.googleapis.com, google fonts, etc, then it start loading, displaying a "connecting to [google-related site]" on the browser bottom, and stall at that point for a long time.  I can browse other sites fine and they load quickly. I can ping the domains with 0% loss and &lt;100ms times. I can ping 8.8.8.8, I am not behind a proxy, there is nothing on my hosts file, I am not at work or in a networked environment: it is a home network behind a router. I connect using wifi (I am too distant to use wired).   Other users on the same network don't have the issue. I can both ping and browse the sites. I have pinged ajax.googleapis.com from my android and my other laptop, and they return the same IP than on this laptop. They also share the same external IP address, according to   The issue happens on ubuntu 12.04, and as it is cyclic but not frequent enough to make sure, I don't honestly remember if it happens on Windows 7 as well (it is a dual-boot machine). Rebooting the router won't help. Rebooting the computer fixes the problem, until it happens again.  It's been happening for a few months now. The last time it happened (earlier today) I performed a ping before and after the reboot. Here's the results:  before  $ping ajax.googleapis.com PING googleapis.l.google.com (74.125.21.95) 56(84) bytes of data. 64 bytes from yv-in-f95.1e100.net (74.125.21.95): icmp_req=1 ttl=47 time=157 ms 64 bytes from yv-in-f95.1e100.net (74.125.21.95): icmp_req=2 ttl=47 time=163 ms 64 bytes from yv-in-f95.1e100.net (74.125.21.95): icmp_req=3 ttl=47 time=156 ms 64 bytes from yv-in-f95.1e100.net (74.125.21.95): icmp_req=4 ttl=47 time=165 ms 64 bytes from yv-in-f95.1e100.net (74.125.21.95): icmp_req=5 ttl=47 time=157 ms 64 bytes from yv-in-f95.1e100.net (74.125.21.95): icmp_req=6 ttl=47 time=155 ms 64 bytes from yv-in-f95.1e100.net (74.125.21.95): icmp_req=7 ttl=47 time=159 ms 64 bytes from yv-in-f95.1e100.net (74.125.21.95): icmp_req=8 ttl=47 time=157 ms   after  $ping ajax.googleapis.com PING googleapis.l.google.com (74.125.134.95) 56(84) bytes of data. 64 bytes from gg-in-f95.1e100.net (74.125.134.95): icmp_req=1 ttl=47 time=207 ms 64 bytes from gg-in-f95.1e100.net (74.125.134.95): icmp_req=2 ttl=47 time=154 ms 64 bytes from gg-in-f95.1e100.net (74.125.134.95): icmp_req=3 ttl=47 time=154 ms 64 bytes from gg-in-f95.1e100.net (74.125.134.95): icmp_req=4 ttl=47 time=152 ms 64 bytes from gg-in-f95.1e100.net (74.125.134.95): icmp_req=5 ttl=47 time=157 ms 64 bytes from gg-in-f95.1e100.net (74.125.134.95): icmp_req=6 ttl=47 time=160 ms 64 bytes from gg-in-f95.1e100.net (74.125.134.95): icmp_req=7 ttl=47 time=154 ms 64 bytes from gg-in-f95.1e100.net (74.125.134.95): icmp_req=8 ttl=47 time=157 ms 64 bytes from gg-in-f95.1e100.net (74.125.134.95): icmp_req=10 ttl=47 time=154 ms 64 bytes from gg-in-f95.1e100.net (74.125.134.95): icmp_req=11 ttl=47 time=152 ms   The issue happens on different browsers, I installed epiphany and it shows the same behaviour.  I have inspected the network tab on firefox and it shows a single, unreplied GET request:   I installed wireshark and listened for HTTP GET requests; on other sites it pops up on the report, but on ajax.googleapis it shows nothing. I listened then for DNS requests, there are some differences:     If connect via telnet to the port 80 of a random site and perform a GET it works, but I can't telnet to ajax.googleapis.com (or it's IP), the connection never completes. Post for clarifications on the updated pronouns FAQ I'm hoping someone can help! I recently downloaded a torrent directly onto an external hard drive, (using a 2009 MacBook Pro and 1TB Seagate Expansion portable Drive) somehow during the download the drive was accidentally ejected, since this incident when I plug the drive back in it’s having problems reading.  The drive works fine for about 10 minutes, I can read/copy/paste and access files but then starts to wreak havoc; apps hangs, it hangs the Finder, etc.  I’ve tried repairing it in Disk Utility, which reads and repairs this disk but problems inevitably continue as described above.  I’ve deleted the Torrent file also. All my files on this external drive so re-formatting is not an option until I can retrieve them. Basically, I want to have a single operator which can do multiple things, based on some attributes values.  class MyPanel(bpy.types.Panel):     # (...)     layout = self.layout     row = layout.row()     row.operator("my.button", text="Button text")  class MY_BUTTON_OT_Button(bpy.types.Operator):     bl_idname = "my.button"     bl_description = "Button description"     bl_label = "Button"     foo = bpy.props.IntProperty()     bar = bpy.props.BoolProperty()      if bar:         # Do something with foo     else:         # Do something else :P   I know how to set one attribute, like so:      row.operator("my.button", text="Button text").foo=5   But what about multiple arguments? I tried several things that didn't worked, like (e.g.):   With setattr(): row.operator("my.button", text="Button text").setattr(foo=5,bar=True)   With a custom method setVal() in the operator class: row.operator("my.button", text="Button text").setVal(foo=5,bar=True)   Maybe I must use a single EnumProperty? I hope to avoid this, so my question is: Is it possible to pass multiple custom arguments to set attributes in an operator class? And if yes, how ?  Thanks for your help. Is there a command for large middle delimiters consistent with \bigl and \bigr? After browsing through related threads, I am now of the understanding (please correct me if I am wrong) that the rule of thumb is to use the \bigl,\bigr pair with brackets, parentheses, etc. for operators like sums, products, and integrals, and \left,\right in all other cases.  I only recently found out about \middle , which has solved what had been a vexing problem for me: delimiters for function arguments (slashes, bars) not scaling properly. Leafing through my cheatsheet has not been of much help, so I wish to ask: is there an equivalent of \middle for \bigl and \bigr, or would the use of \middle along with that pair not be gauche? Can awakened mind be used with suggestion? Can the warlock class feature "awakened mind" be used in conjunction with the suggestion spell, allowing the warlock to make the suggestion telepathically?  Awakened Mind, Player's Handbook p. 110:     You can telepathically speak to any creature you can see within 30 feet of you. You don't need to share a language with the creature for it to understand your telepathic utterances.   Suggestion, Player's Handbook p. 279:     You suggest a course of activity (limited to a sentence or two) and magically influence a creature you can see within range that can hear and understand you.   If it works with suggestion, would it also work with mass suggestion?  To be clear, I am not asking about the verbal component of the spell, only the method the caster "suggests a course of activity".