473,806 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading input and writing output

For some reason, I'm getting an error. It doesn't seem to be reading
my "input.txt" file. I'm trying to read the "input.txt" file which
consits of random integers and use insertion sort to sort them in
order. Then, i want to have the sorted integers go the file
"output.txt "

static final int MAX_NUM = 100;

public static void main( String[] args ) throws java.io.IOExcep tion
{
int[] num = new int[MAX_NUM];

FileReader fr = new FileReader("inp ut.txt");
BufferedReader br = new BufferedReader( fr );
PrintWriter out = new PrintWriter( new BufferedWriter( new FileWriter(
"output.txt " ) ) );

int count = 0;
while ( count < MAX_NUM )
{
String line = br.readLine();
if( (line == null) || line.equals( "" ) )
break;
try
{
num[count] = Integer.parseIn t( line );
count++;
}
catch( Exception e)
{
System.out.prin tln( "ERROR" );
}
//System.out.prin tln( line );
//line = br.readLine();
}
insertionSort( num );

for( int i = 0; i < count; i++ )
{
out.println( Integer.toStrin g( num ) );
}

out.close();
}
*---------------------------------*
Posted at: http://www.GroupSrv.com
Check: http://www.HotCodecs.com
*---------------------------------*
Jul 17 '05 #1
2 4588
slickn_sly wrote:
For some reason, I'm getting an error. It doesn't seem to be reading
my "input.txt" file. I'm trying to read the "input.txt" file which
consits of random integers and use insertion sort to sort them in
order. Then, i want to have the sorted integers go the file
"output.txt "

====cut cut======

what kind of error do you get? at what line? try to be more specific,
maybe copy & paste error message.
suggestion: try to print on standard output first (System.out), once you
are sure it works well, print it to the file.
Are you sure the file is in the same directory/folder as your program?
btw ever used the java debugger? it's a handy tool sometimes very useful.

cheerz
oc
--
All our questions are porcelain
Jul 17 '05 #2
"slickn_sly " <bn***@hotmai l-dot-com.no-spam.invalid> wrote in message
news:41******** **@127.0.0.1...
[...]
You will get more replies if you direct your posts to comp.lang.java. help in the
future. This group is deprecated.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
5232
by: dbuser | last post by:
Hi, I need help on a problem, as described below. I am reading a file "input.txt"which has data like this: abc def gh izk lmnopq rst uvwxyz I am using fstream object to read the file and writing into a dynamic array. My problem is that the array shows extra z and probably because of this further processing gives run time error in borland compiler. Can you please tell me, if the problem is related to handling end-of line , how do i do...
4
7264
by: Jeff Rodriguez | last post by:
How would one go about reading a file line by line in reverse? For Example: -- FILE -- 1 2 3 4 5 -- FILE --
3
3289
by: RJN | last post by:
Hi I've a template excel file which has all the calculations defined. There are certain input values to be entered which gives a lot of output to the user. I don't want to expose the excel sheet to the user as calculations become visible. I'm writing a web interface which takes the input values from user, updates the excel sheet and returns the recalculated output from the excel file. I'm using ADO.Net to update and read the excel file.
10
8362
by: Tyler | last post by:
Hello All: After trying to find an open source alternative to Matlab (or IDL), I am currently getting acquainted with Python and, in particular SciPy, NumPy, and Matplotlib. While I await the delivery of Travis Oliphant's NumPy manual, I have a quick question (hopefully) regarding how to read in Fortran written data. The data files are not binary, but ASCII text files with no formatting and mixed data types (strings, integers,...
13
3716
by: swetha | last post by:
HI Every1, I have a problem in reading a binary file. Actually i want a C program which reads in the data from a file which is in binary format and i want to update values in it. The file consists of structures of type---- struct record { int acountnum; char name; float value;
21
3073
by: Stephen.Schoenberger | last post by:
Hello, My C is a bit rusty (.NET programmer normally but need to do this in C) and I need to read in a text file that is setup as a table. The general form of the file is 00000000 USNIST00Z 00000000_00 0 000 000 000 0000 000 I need to read the file line by line and eventually parse out each piece of the file and store in arrays that correspond to the specific
1
1519
by: kals | last post by:
i have written the code for reading and writing an image file but the problem is that its output image is not the same as input......i.e output is some random image consisting of scribbled black and white lines. not able to understand wat the problem could be ???? i am using fread and fwrite and reading and writing in binary form.
4
2152
by: radhikams | last post by:
hi I have written a code for writing the data of a column from database into a file and again reading that file and displaying. Im writing into an .html file....Now the problem is im getting the output but that output is followed by an error..... This is the output ----------------------------- A large number of processes are available, and can be applied to an input or a group of inputs. These processes can be chained...
2
2521
by: ccarter45 | last post by:
Help! I need to write a program that reads a text file with numbers and sums up each line of numbers. Then write a part of the program that outputs the text to another file. How do I do this? Here's what the data file looks like: 1 2 2 3 3 4 4 5 5 6 Here is the code I have: import java.util.Scanner;
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10617
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10370
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.