ioexception


PrintWriter doesn't seem to be writing to file even though I'm closing it


I'm trying to use PrintWriter to print into a predetermined .txt file called output.txt.
I've not tried putting both File and FileWriter inside PrintWriter, and having no luck. I'm closing it too. Weirdest part of it is that another similar use of PrintWriter in my other code seems to be working perfectly fine (the 2nd one).
Could someone flick me some pointers/hints please?
public static void main(String[] args) throws IOException{
if(args.length <4){
return;
}else{
String patternFileN = args[0];
String sequenceFileN = args[1];
int numOfSeqs = Integer.parseInt(args[2]);
int pattInd = Integer.parseInt(args[3]);
if(numOfSeqs <= 0){
return;
}
String pattern;
String[] txtSequence = new String[numOfSeqs];
PrintWriter outFile = null;
try{
String outFileN = "output.txt";
outFile = new PrintWriter(new File(outFileN));
for(int seqInd = 0; seqInd < numOfSeqs; seqInd++){
int offset = RKscanner.seqSearch(txtSequence[seqInd]);
if(offset < txtSequence[seqInd].length()){
//outFile.println(pattInd + " " + seqInd);
outFile.println("nigaaaa");
}
}
}catch(IOException e){
e.printStackTrace();
System.err.println("files couldn't be opened");
}finally{
outFile.close();
}
}
}
This code is working fine:
public static void main(String[]args) throws IOException{
int letters = 4;
int pattLength, possNum; //number of possible sequences
try{
if(args.length <=1){
System.err.println("please specify output filename & lengths of patterns to be generated");
System.err.println("---try: java patternGen pattern.txt 5");
}else{
String fileName = args[0];
PrintWriter outFile = new PrintWriter(new FileWriter(fileName));
pattLength = Integer.parseInt(args[1]);
possNum = (int)Math.pow(letters, pattLength); //possible number of combinations without wildcards.
//Nucleotide[][] patternBuild = new Nucleotide[possNum][pattLength];//the built pattern to be used for consructor.
StringBuilder sb = new StringBuilder(pattLength);
for(int i = 0; i < possNum; i++){
sb.setLength(0);
StringBuilder alphToNuc = new StringBuilder(0);
String sbStore = sb.toString();
//...then string builders populated
//System.out.println("alphabet: "+sb);
outFile.println(alphToNuc);
System.out.println(alphToNuc);
}
outFile.close();
}
}catch(IOException e){
e.printStackTrace();
}
}
FIXED!
The problem was that I was running these java files with a bash script in a loop, so the file would overwrite When I open and wrote into these files in the java files.
Sorry for irrelevantly topiced question

Related Links

java.io.IOException: Incorrect configuration: namenode address dfs.namenode.servicerpc-address or dfs.namenode.rpc-address is not configured
How to cancel request using merge
PrintWriter doesn't seem to be writing to file even though I'm closing it
StreamWriter.Writeline throws “Not enough storage is available to process this command.” IO exception
IO Exception in OSMembrane while executing pipeline
Exception in thread Main Error java.lang.numberformat.exception
java.io.IOException: The filename, directory name, or volume label syntax is incorrect Error while writing to HTTP directory

Categories

HOME
rust
visual-studio
knockout.js
opencart
blast
yaml
loopbackjs
typeerror
bing-search
nsis
mirc
position
save
lapack
sap-fiori
buffer
jquery-select2-4
grocery-crud
amazon-elb
squid
async-await
hidden
boomi
parceler
gitkraken
android-permissions
workday
coreldraw
stackexchange.redis
android-service
npoi
sparkle
openbr
steam-web-api
caesar-cipher
microsoft-certifications
counting
markov-chains
gnu-classpath
restful-architecture
transform
pdfminer
ms-dos
recovery
cheat-engine
extbase
praat
best-buy-api
icepdf
secure-coding
raytracing
supertest
phppgadmin
punctuation
1010
mpmovieplayercontroller
finder
elastic4s
xcode6.4
msg
openquery
jpda
openseadragon
android-sdcard
apache-pig-grunt
maximize
cortana
phpquery
stack-smash
calcite
hmisc
unhandled
unidata
quercus
kognitio-wx2
mojo
sunos
cakephp-2.2
iodocs
lmax
oracle-adf-mobile
coding-efficiency
maven-central
rails-api
fileshare
sql-function
discovery
grails-2.3
objective-c-runtime
jacob
axacropdf
asp.net-mvc-3-areas
spark-view-engine
pageheap
exponent
database-deadlocks
django-pagination
icicles
ixmldomdocument

Resources

Encrypt Message