The Artima Developer Community
Sponsored Link

Java Answers Forum
output file to notepad

1 reply on 1 page. Most recent reply: Oct 18, 2004 10:12 AM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
jihan

Posts: 1
Nickname: yandolce
Registered: Oct, 2004

output file to notepad Posted: Oct 17, 2004 1:45 PM
Reply to this message Reply
Advertisement
my program works in such a way that it will ouput to a notepad. i did both printing in command prompt and and printWriter.. output the file to notepad.. yes the program can run in command prompt, but my output.txt appears to be 0kb. im not sure why. this is the file where i write the codes to output to notepad. anybody can tell me the mistake?

import java.io.*;
public class dotplot
{
private controller control;
private String xStr = ""; // Test sequence1
private String yStr = ""; // Test sequence2
private int winSize; // The sliding windows size private int stringency; // The stringency of the sliding window
final static int SIZE = 100; // The maximum length of the sequence

static int [][] match = new int [SIZE][SIZE];
static char [][] overlay = new char [SIZE][SIZE]; // May use int[][] array
static char x[] = new char [SIZE];
static char y[] = new char [SIZE];
static final int CMATCH = 1;
int winMatch = 0;

private static File file = null;
private static FileWriter fileWriter = null;
private static PrintWriter printWriter = null;

public dotplot()
{
control = new controller();
xStr = control.getseq1();
yStr = control.getseq2();
winSize = control.getwinsize();
stringency = control.getstringency();
}

// Initialization of array
public void init() throws IOException
{
try //print to notepad {
file = new File("C:\\Documents and Settings\\JiHaN\\My Documents\\My eBooks\\JavaPrograms\\dotplot(Jihan)\\output.txt");
if (file != null)
{
fileWriter = new FileWriter(file);
printWriter = new PrintWriter(fileWriter);
}

for (int i=0; i < SIZE; i++) {
for (int j=0; j < SIZE; j++) {

match[j] = 0;
overlay[j] = '.';

}
}

fileWriter.close();

} catch (IOException e)
{
System.out.print(e.toString());
printWriter.print(e.toString());
}
finally
{

}
}

public void print() throws IOException
{
System.out.println("Starting DotPlot...");
System.out.println("");
init();

// Place the sequences in two char arrays
// Using char array is much simple and more efficient
xStr.getChars(0, xStr.length(), x, 0);
yStr.getChars(0, yStr.length(), y, 0);

// This is the easier part. Find matching character pair
for (int i=0; i < xStr.length(); i++) {
for (int j=0; j < yStr.length(); j++) {
// This is the part that determine which location in the graph if (x == y[j])
match[j] = CMATCH;
}

}
}
// This is the sliding Window TECHNIQUE code portion public void slidingWindow() throws IOException
{

for (int i=0; i < xStr.length()-winSize+1; i++) {
for(int j=0; j < yStr.length()-winSize+1; j++) {
for(int k=0,l=0; (k<winSize)||(l<winSize); k++,l++){


if(k==l){
if(match[k+i][l+j] == 1)
winMatch++;
}

if(winMatch == stringency){
overlay[j] = 'o';
winMatch = 0;
}
}
}

}
}

// Output Printing
public void printOutput() throws IOException
{
print();


System.out.println("The length of xStr is " + xStr.length());
printWriter.println("The length of xStr is " + xStr.length());
System.out.println("The length of yStr is " + yStr.length());
printWriter.println("The length of yStr is " + yStr.length());
System.out.println("");
printWriter.println("");

//print out the sequence n plot it.
System.out.print(" "); // Two spaces for the xStr
printWriter.println(" ");
for (int j=0; j < yStr.length(); j++)
System.out.print(y[j] + " ");
for (int j=0; j < yStr.length(); j++)
printWriter.print(y[j] + " ");
System.out.println("\n");
printWriter.println("\n");

for (int i=0; i < xStr.length(); i++) {
System.out.print(x);
printWriter.print(x);
for (int j=0; j < yStr.length(); j++) {
if (match[j] == CMATCH){
System.out.print(" x");
printWriter.print(" x");
}
else
{
System.out.print(" ");
printWriter.print(" ");
}

}
System.out.println("\n");
printWriter.println("\n");

}
}

public void printSliding() throws IOException
{
slidingWindow();

System.out.println("Sliding window..");
printWriter.println("Sliding window..");
System.out.println("");
printWriter.println("");
System.out.print(" "); // Two spaces for the xStr
printWriter.print(" ");
for (int j=0; j < yStr.length(); j++)
System.out.print(y[j] + " ");
for (int j=0; j < yStr.length(); j++)
printWriter.print(y[j] + " ");
System.out.println("\n");
printWriter.println("\n");

for (int i=0; i < xStr.length(); i++) {
System.out.print(x);
printWriter.print(x);
for (int j=0; j < yStr.length(); j++) {
if (overlay[j] == 'o') {
System.out.print(" o");
printWriter.print(" o");
}
else
{
System.out.print(" ");
printWriter.print(" ");
}

}
System.out.println("\n");
printWriter.println("\n");


printWriter.clo se();

}
}
}


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: output file to notepad Posted: Oct 18, 2004 10:12 AM
Reply to this message Reply
Your PrintWriter may not be set up right.

Try using the PrintWriter that takes in the
boolean argument true.

PrintWriter pr = new PrintWriter(YourOutPutStream, true);

In your case you have a file OutPut Stream.

Flat View: This topic has 1 reply on 1 page
Topic: javax.comm ring detected Previous Topic   Next Topic Topic: entrySet() Analysis

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use