Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 28-04-2009
Member
 
Join Date: Nov 2008
Posts: 20
Sending data to a file

Hi,

The problem i'm having is that the data that i want to appear on the file doesnt apear fully. I want the full results of the program to be saved to a doc file but i only get the next number in the sequence. Here is my code

<code>
# import java.io.*;

# public class identify2 {
# int N=1;
# char[] BitStream=new char[569878];
# double[] Entropy=new double[30];
# int MaxLength=0;
# boolean EOF;

// read data from a text file
# void ReadData()
# {
# System.out.println("after here would be a read data");


# try
# {
# String fileName="f:\\malay-binary3.txt";

# File input=new File(fileName);

# PushbackReader in=new PushbackReader(new BufferedReader(new FileReader(input)));

#
int c = 1;

# int i = 0;
# while(c!=-1)
# {String number="";

# c = in.read();
# MaxLength+=1;

# if(c==-1)
# break;
# else
# in.unread(c);


# BitStream[i]=(char)(in.read());

# i++;

# }//end of try

# }
# catch(EOFException e)
# {EOF=true;}

# catch(FileNotFoundException e)
# {System.err.println(e);
# return;
# }
# catch(IOException e)
# {System.err.println("Err reading input file"+e);
# return;
}
# } //end of ReadData

//analyize the data (chunk and calculate the entropy )
# void processfile()
# {
# int Find = 0,f = 0,f1 = 0,p,N_entropy,L,Length = 0, index = 0,end_index=0;
# double Probability, Local_Entropy = 0.0;

# int Frequency[] = new int[MaxLength];
# String Patterns[] = new String[MaxLength];
# String Pattern = "";

# Length = MaxLength;

# for( N = 1; N <=3; N++ )
# {
# System.out.println("When N=" + N);

// for every fixed length N has N entropy
# for ( N_entropy=0;N_entropy< N ;N_entropy++ )
# {
# L = Length - N_entropy;
# index = N_entropy;
# end_index = index + (L / N -1) * N ;

# for ( index = N_entropy; index<=end_index; index+=N )
# {
# for ( p= index; p < index+N; p++ )
# Pattern += BitStream[p];

# for (int m=0; m<f; m++ )
# {
# if( Patterns[m].equals(Pattern) && (Find==0) )
# { Find = 1;
# f1 = m;
}
# }

# if (Find == 1)
# { Frequency[f1] += 1;

# Pattern = "";
# Find = 0;
# }
# else
# {
# Patterns[f] = Pattern;

# Frequency[f] += 1;

# f +=1;
# Pattern = "";}

} //end of for index


# f=0;
# int Patterns_N = L/N; //how many patterns of N length contains in the BitStream

# do
{ Probability = (double)(Frequency[f])/(double)(Patterns_N); //Probability of Patterns

# Local_Entropy += Probability * ( Math.log(Probability)/Math.log(2));

# f+=1;
}
# while (Frequency[f]!=0);

# Entropy[N_entropy] = (-Local_Entropy);
# System.out.println("Entropy(" + N_entropy + ")=" + Entropy[N_entropy]);

// initialize the variables
# f=0;
# for (int i=0;i<MaxLength;i++)
# {Frequency[i] =0;
# Patterns[i] = "";}


# Pattern="";
# f=0;f1=0;
# Find=0;
# Local_Entropy=0;
# p=0;

# }
# System.out.println();

# }//end of for "N"

# }

//output the result to a text file
# void writeData()
# {

# try
# {
# String fileName="f:\\test86.doc";
# File output=new File(fileName);
# output.createNewFile();

# if(!output.isFile())
# {System.out.println("Creating"output.getPath()"failed.");
# return;
# }

# BufferedWriter out=new BufferedWriter(new FileWriter(output.getPath(),true));
# out.write("Then entropy of length " + N + ":" + "\n");
# for( int i = 0; i < N; i++ )
# {
# //System.out.println("En[i]="+Entropy[i]);
# out.write(Double.toString( Entropy[i] ) + "\n");

# }
# out.write( "\n" );
# out.close();

# }//end of try

# catch(IOException e)
# {System.out.println("Error writing the file"+e);}
}// end of writeData

//main class

# public static void main(String[] args)
# {
# identify2 test=new identify2();

# test.ReadData();
# test.processfile();
# test.writeData();
}

}

<code>
it should give me the following when it is saved to the doc file
after here would be a read data
When N=1
Entropy(0)=1.0000741842259357

When N=2
Entropy(0)=1.9998076934003925
Entropy(1)=1.99996372281124

When N=3
Entropy(0)=2.994268823400294
Entropy(1)=2.993906140011204
Entropy(2)=2.9948443499810233

but it gives me
Then entropy of length 4:
2.994268823400294
2.993906140011204
2.9948443499810233
0.0

Any help would be greatly apperciated. Thank you for your help in advance
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Sending data to a file"
Thread Thread Starter Forum Replies Last Post
Sending data to Javacard through APDU / Signature Max-well Software Development 5 24-07-2010 03:29 AM
Delete a file locally after sending to ftp KADRI Networking & Security 3 29-10-2009 06:02 PM
How to pop up Interactive map by sending data from MYSQL using PHP Neil'o Software Development 3 14-09-2009 11:47 PM
'Document Contains No Data' while Sending and Receiving Simpson Technology & Internet 2 05-05-2009 07:18 PM
Sending an MP3 file with Thunderbird Rock Villa Technology & Internet 4 17-04-2009 07:35 PM


All times are GMT +5.5. The time now is 04:06 AM.