Java FileOutputStream Windows/Linux - java

Hy I got this Code:
OutputStream output = new FileOutputStream("res/" + new java.util.Date().toString() +".properties");
I'm working on my Code at university (Laptop - Ubunutu) and at home (Desktop - windows).
I Sync the Eclipse Project with github and EGit.
Now I wasn't able to excecute this line of code on my Windows machine, but it's still working on my laptop.. the exact same Code..
Getting the Error:
java.io.FileNotFoundException: res\Thu Jan 08 15:54:39 CET 2015.properties (Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch)
And: at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Sourc
at java.io.FileOutputStream.<init>(Unknown Source)

Windows does not allow colons ':' in filenames.

I think the problem is that : is not a valid character for a path name in Windows.
From the MSDN article "Naming Files, Paths, and Namespaces":
[...]
Use any character in the current code page for a name, including
Unicode characters and characters in the extended character set
(128–255), except for the following:
The following reserved characters:
< (less than)
> (greater than)
: (colon)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)
[...]

new java.util.Date().toString() will give date in following format
Thu Jan 08 20:51:01 IST 2015
It contains :
That character is not allow to use in names in windows. But you can use them in linux
Therefore if you want to use same thing in both platform, you have to change the format of the date may be using SimpleDateFormat or something else
e.g.
SimpleDateFormat sd = new SimpleDateFormat("YY-MM-DD");
System.out.println(sd.format(new Date()));

Related

Running an Imported android project

I have a problem with running an imported android project. In fact, when i run it i get an error from BuildConfig.java ( this file is not editable) the error is
"Error:(18, 69) error: illegal escape character".
and this is the line that the error is pointing to:
public static final String[] TRANSLATION_ARRAY = new String[]{"C:\gpslogger\gpslogger\src\main\res\values","C:\gpslogger\gpslogger\src\main\res\af","C:\gpslogger\gpslogger\src\main\res\ar","C:\gpslogger\gpslogger\src\main\res\ca","C:\gpslogger\gpslogger\src\main\res\cs","C:\gpslogger\gpslogger\src\main\res\cy","C:\gpslogger\gpslogger\src\main\res\da","C:\gpslogger\gpslogger\src\main\res\de","C:\gpslogger\gpslogger\src\main\res\el","C:\gpslogger\gpslogger\src\main\res\es","C:\gpslogger\gpslogger\src\main\res\es-ES","C:\gpslogger\gpslogger\src\main\res\es-MX","C:\gpslogger\gpslogger\src\main\res\es-PE","C:\gpslogger\gpslogger\src\main\res\fa","C:\gpslogger\gpslogger\src\main\res\fi","C:\gpslogger\gpslogger\src\main\res\fr","C:\gpslogger\gpslogger\src\main\res\fr-CA","C:\gpslogger\gpslogger\src\main\res\gl","C:\gpslogger\gpslogger\src\main\res\he","C:\gpslogger\gpslogger\src\main\res\hi","C:\gpslogger\gpslogger\src\main\res\hr","C:\gpslogger\gpslogger\src\main\res\hu","C:\gpslogger\gpslogger\src\main\res\is","C:\gpslogger\gpslogger\src\main\res\it","C:\gpslogger\gpslogger\src\main\res\ja","C:\gpslogger\gpslogger\src\main\res\ko","C:\gpslogger\gpslogger\src\main\res\lt","C:\gpslogger\gpslogger\src\main\res\lv","C:\gpslogger\gpslogger\src\main\res\mk","C:\gpslogger\gpslogger\src\main\res\ms","C:\gpslogger\gpslogger\src\main\res\nl","C:\gpslogger\gpslogger\src\main\res\no","C:\gpslogger\gpslogger\src\main\res\pl","C:\gpslogger\gpslogger\src\main\res\pt","C:\gpslogger\gpslogger\src\main\res\pt-BR","C:\gpslogger\gpslogger\src\main\res\pt-PT","C:\gpslogger\gpslogger\src\main\res\ro","C:\gpslogger\gpslogger\src\main\res\ru","C:\gpslogger\gpslogger\src\main\res\sk","C:\gpslogger\gpslogger\src\main\res\sl","C:\gpslogger\gpslogger\src\main\res\sr","C:\gpslogger\gpslogger\src\main\res\sv","C:\gpslogger\gpslogger\src\main\res\sv-SE","C:\gpslogger\gpslogger\src\main\res\ta","C:\gpslogger\gpslogger\src\main\res\th","C:\gpslogger\gpslogger\src\main\res\tl","C:\gpslogger\gpslogger\src\main\res\tr","C:\gpslogger\gpslogger\src\main\res\uk","C:\gpslogger\gpslogger\src\main\res\vi","C:\gpslogger\gpslogger\src\main\res\zh","C:\gpslogger\gpslogger\src\main\res\zh-CN","C:\gpslogger\gpslogger\src\main\res\zh-TW"};
\g is an illegal escape character in "C:\gps..."
All windows path strings need to have \\, for example "C:\\"
You should find the file that is editable and correct those strings
P.S. the (18, 69) in the error means line 18, column 69 of the file.

Java regex is working in my system but not in the server

The regular expression is
String regex = "^[\\p{IsHangul}\\p{IsDigit}]+";
And whenever i do
text.matches(regex);
It works fine in my system but not in some of the system.
I am not able to track the issue.
Thank you in advance.
Exception:
Exception in thread "main" java.util.regex.PatternSyntaxException: Unknown character property name {Hangul} near index 13
^[\p{IsHangul}\p{IsDigit}]+
^
at java.util.regex.Pattern.error(Pattern.java:1713)
at java.util.regex.Pattern.charPropertyNodeFor(Pattern.java:2437)
at java.util.regex.Pattern.family(Pattern.java:2412)
at java.util.regex.Pattern.range(Pattern.java:2335)
at java.util.regex.Pattern.clazz(Pattern.java:2268)
at java.util.regex.Pattern.sequence(Pattern.java:1818)
at java.util.regex.Pattern.expr(Pattern.java:1752)
at java.util.regex.Pattern.compile(Pattern.java:1460)
at java.util.regex.Pattern.<init>(Pattern.java:1133)
at java.util.regex.Pattern.compile(Pattern.java:823)
at java.util.regex.Pattern.matches(Pattern.java:928)
at java.lang.String.matches(String.java:2090)
at com.mycompany.helper.ApplicationHelper.main(ApplicationHelper.java:200)
According to Using Regular Expressions in Java:
Java 5 fixes some bugs and adds support for Unicode blocks. ...
Make sure you're using Java 5+ in the server.
It seems that Java version you are using is not able to recognise Hangul as correct script character so you can try to create your own character class which will cover same range as Hongul from newer versions of Java.
From what I see in code in source code of Character.UnicodeScript on Java 8 Hangul refers to Unicode ranges
1100..11FF
302E..302F
3131..318F
3200..321F
3260..327E
A960..A97F
AC00..D7FB
FFA0..FFDF
so maybe try with such pattern
Pattern.compile("^["
+ "\u1100-\u11FF"
+ "\u302E-\u302F"
+ "\u3131-\u318F"
+ "\u3200-\u321F"
+ "\u3260-\u327E"
+ "\uA960-\uA97F"
+ "\uAC00-\uD7FB"
+ "\uFFA0-\uFFDF"
+ "\\p{IsDigit}]+");

DecimalFormat not working on Windows 7, but working on Windows 8

I have an applet which is working fine on Windows 8, but on Windows 7 I get the following error:
Exception in thread "Thread-13" java.lang.NumberFormatException: For input string: "-0,9"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Float.parseFloat(Unknown Source)
at Tanc.Game$Corp.getDW(Game.java:1505)
at Tanc.Game.borders(Game.java:975)
at Tanc.Game.loose(Game.java:1068)
at Tanc.Game.gameLoop(Game.java:242)
at Tanc.Game$1.run(Game.java:144)
I have to mention that I tried on 2 different computers but the same problem. On Windows 8 I don't get this error...
And code
String zz = new DecimalFormat("#.##").format(corp400.y);
System.out.println(zz);
if (Float.parseFloat(zz) == 0.2f)
sw = true;
if (Float.parseFloat(zz) == -0.24f)
sw = false;code here
Probably problem with locale: on the computer with Win8 there are locale, where , means decimal separator, but on the other tested computers . means decimal separator.
I replaced DecimalFormat with (Math.round(corp400.y*100.0)/100.0)
But if anyone can find out how to fix DecimalFormat to work with Windows 8 and windows 7 please Comment/Answer.
Probably on windows 8 (where it works) you are using an English locale.
The problem, tough, is in the code:
String zz = new DecimalFormat("#.##").format(corp400.y);
actually uses the default locale to format corp400.y, but the JavaDoc says that Float.parseFloat
Returns a new float initialized to the value represented by the specified String, as performed by the valueOf method of class Float.
This means that, since Float.valueOf parses a floating point literal, it expects decimals separated by . not ,
The correct way to reverse your locale-dependant formatting is:
float value = new DecimalFormat("#.##").parse(zz).floatValue();
Alternatively, you could use the locale-independent formatting on both ways as in:
String zz = String.valueOf(corp400.y);
float value = Float.parseFloat(zz)

Why do I see scrabbled output when using JSch?

I am trying to use JSch. I tried the example here
Although I can connect the output is weird.
I get the following:
Last login: Thu Jan 31 19:44:25 2013 from 10.2.251.77
[1mcli:~ # [m
And if I do e.g. an ls I get:
[0m[01;34m.InstallAnywhere[0m [00m.bash_history [00m.bash_profile[0m
[01;34mbin[0m [00msles11-patched[0m
[01;34m.kbd[0m [00mindex.html[0m [00mtest.sql[0m
[00m.viminfo[0m [00;31mipvsadm-1.26-1.src.rpm[0m
[m[1mcli:~ # [m
These are the directory contents but why are they displayed like that?
I am running in this from Eclipse and this is what I see in Eclipse output. If I run this from Windows CMD it stucks
Update:
I noticed that if I connect to a different linux the output is fine!
Only if I connect to a specific linux installation I see these weird characters! Any idea what is causing this?
Update2:
Following the link of #PeterMmm I did printf "äöü" | xxd. Both the "bad" and good one give:
0000000: e4f6 fc
I also did locale.
In the "bad" case:
# locale
LANG=POSIX
LC_CTYPE=en_US.UTF-8
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
In the good system:
LANG=POSIX
LC_CTYPE=en_US.UTF-8
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
Configuration seems to be the same. So what could be causing this?
Please check
Funny Shell Output: [01;32mtestfile.txt[00m instead of testfile.txt
((ChannelShell) channel).setPtyType("dumb");
Does the trick.
They are escape sequences for the terminal emulation. I guess that there is no relation to the character encoding.
Update:
If ChannelShell#setPty(false) is invoked, a pseudo-terminal will not be allocated and escape sequences will not be appeared.
Channel channel=session.openChannel("shell");
((ChannelShell)channel).setPty(false); // !!
...
channel.connect();

How to train the Stanford Parser with Genia Corpus?

I have some problems to create a new model for Stanford Parser.
I have also downloaded the last version from Stanford:
http://nlp.stanford.edu/software/lex-parser.shtml
And here, Genia Corpus in 2 formats, xml and ptb (Penn Treebank).
Standford Parser can train with ptd files ; then I downloaded Genia Corpus, because I want to work with biomedical text:
http://categorizer.tmit.bme.hu/~illes/genia_ptb/ (link no longer available) (genia_ptb.tar.gz)
Then, I have a short Main class to get dependency representation of one biomedical sentence:
String treebankPath = "/stanford-parser-2012-05-22/genia_ptb/GENIA_treebank_v1/ptb";
Treebank tr = op.tlpParams.diskTreebank();
tr.loadPath(treebankPath);
LexicalizedParser lpc=LexicalizedParser.trainFromTreebank(tr,op);
I have tried different ways, but always get the same result.
I have an error in the last line. This is my output:
Currently Fri Jun 01 15:02:57 CEST 2012
Options parameters:
useUnknownWordSignatures 2
smoothInUnknownsThreshold 100
smartMutation false
useUnicodeType false
unknownSuffixSize 1
unknownPrefixSize 1
flexiTag true
useSignatureForKnownSmoothing false
parserParams edu.stanford.nlp.parser.lexparser.EnglishTreebankParserParams
forceCNF false
doPCFG true
doDep false
freeDependencies false
directional true
genStop true
distance true
coarseDistance false
dcTags false
nPrune false
Train parameters: smooth=false PA=true GPA=false selSplit=true (400.0; deleting [VP^SQ, VP^VP, VP^SINV, VP^NP]) mUnary=1 mUnaryTags=false sPPT=false tagPA=true tagSelSplit=false (0.0) rightRec=true leftRec=false collinsPunc=false markov=true mOrd=2 hSelSplit=true (10) compactGrammar=3 postPA=false postGPA=false selPSplit=false (0.0) tagSelPSplit=false (0.0) postSplitWithBase=false fractionBeforeUnseenCounting=0.5 openClassTypesThreshold=50 preTransformer=null taggedFiles=null
Using EnglishTreebankParserParams splitIN=4 sPercent=true sNNP=0 sQuotes=false sSFP=false rbGPA=false j#=false jJJ=false jNounTags=false sPPJJ=false sTRJJ=false sJJCOMP=false sMoreLess=false unaryDT=true unaryRB=true unaryPRP=false reflPRP=false unaryIN=false sCC=1 sNT=false sRB=false sAux=2 vpSubCat=false mDTV=2 sVP=3 sVPNPAgr=false sSTag=0 mVP=false sNP%=0 sNPPRP=false dominatesV=1 dominatesI=false dominatesC=false mCC=0 sSGapped=4 numNP=false sPoss=1 baseNP=1 sNPNNP=0 sTMP=1 sNPADV=1 cTags=true rightPhrasal=false gpaRootVP=false splitSbar=0 mPPTOiIN=0
Binarizing trees...done. Time elapsed: 141 ms
Extracting PCFG...done. Time elapsed: 56 ms
Compiling grammar...done Time elapsed: 1 ms
Extracting Lexicon...Exception in thread "main" edu.stanford.nlp.util.ReflectionLoading$ReflectionLoadingException: edu.stanford.nlp.util.MetaClass$ClassCreationException: java.lang.ClassNotFoundException: edu.stanford.nlp.parser.lexparser.EnglishUnknownWordModelTrainer
at edu.stanford.nlp.util.ReflectionLoading.loadByReflection(ReflectionLoading.java:39)
at edu.stanford.nlp.parser.lexparser.BaseLexicon.initializeTraining(BaseLexicon.java:335)
at edu.stanford.nlp.parser.lexparser.LexicalizedParser.getParserFromTreebank(LexicalizedParser.java:800)
at edu.stanford.nlp.parser.lexparser.LexicalizedParser.trainFromTreebank(LexicalizedParser.java:226)
at edu.stanford.nlp.parser.lexparser.LexicalizedParser.trainFromTreebank(LexicalizedParser.java:237)
at ABravoDemo.main(ABravoDemo.java:35)
Caused by: edu.stanford.nlp.util.MetaClass$ClassCreationException: java.lang.ClassNotFoundException: edu.stanford.nlp.parser.lexparser.EnglishUnknownWordModelTrainer
at edu.stanford.nlp.util.MetaClass.createFactory(MetaClass.java:353)
at edu.stanford.nlp.util.MetaClass.createInstance(MetaClass.java:370)
at edu.stanford.nlp.util.ReflectionLoading.loadByReflection(ReflectionLoading.java:37)
... 5 more
Caused by: java.lang.ClassNotFoundException: edu.stanford.nlp.parser.lexparser.EnglishUnknownWordModelTrainer
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at edu.stanford.nlp.util.MetaClass$ClassFactory.construct(MetaClass.java:119)
at edu.stanford.nlp.util.MetaClass$ClassFactory.<init>(MetaClass.java:192)
at edu.stanford.nlp.util.MetaClass$ClassFactory.<init>(MetaClass.java:53)
at edu.stanford.nlp.util.MetaClass.createFactory(MetaClass.java:349)
... 7 more
How could I create a new model with this corpus ?
As andrucz stated in his comment, the real cause of your problem seems to stem from a missing class.
Try checking whether you correctly imported your library ( and make sure that it contains the class EnglishUnknownWordModelTra‌​iner in edu.stanford.nlp.parser.lexparser.
(If you're using Maven, verify that you correctly added the dependency - a quick google brougt this up : Stanford Parser Maven Repo )
Did the NLP library install correctly?
Check in the logs to verify there are no errors. Most of the times this issue comes when there the stanford nltk library does not install correctly.
A quick way to check is by running the GUI to try out the parser if that runs successfully then the library installed correctly otherwise if that throws errors then you know your installation was poor.
The Stanford website also mentions this take a look:
If you're new to parsing, you can start by running the GUI to try out the parser. Scripts are included for linux (lexparser-gui.sh) and Windows (lexparser-gui.bat).
Take a look at the Javadoc lexparser package documentation and LexicalizedParser class documentation. (Point your web browser at the index.html file in the included javadoc directory and navigate to those items.)
Look at the parser FAQ for answers to common questions.
If none of that helps, please see our email guidelines for instructions on how to reach us for further assistance.
Check whether you have correctly imported library and make sure that it is containing the class {EnglishUnknownWordModelTra‌​iner} and also make sure that version you downloaded properly works with Genia Corps.

Categories

Resources