I wrote a program to write data in a text file to another text file .what i want to do is to open that modified second text file once I've entered data in to that

I wrote a program to write data in a text file to another text file .what i want to do is to open that modified second text file once I've entered data in to that

Have you written any filehandler?
Is your data saved as plain text (filename .txt) or as objects (filename .dat)?
Because you use different streams to read ".txt" or ".dat".

Is the data be to shown in a terminal whit System.out.print() or in an GUI or applet?

Member Avatar for harsh2327

You can use FileReader class under java.io package. Use read method to read the file.

to read a line at a time

public class FileLineReader extends FileReader {
    FileLineReader(File fileName) throws IOException {
    	super(fileName);
    }

String readLine() throws IOException{
		String line = "";
		int temp;
		while((temp=read())!='\n')
		{
			if(temp==-1)
				return line;  // End of file
			line+=(char)temp + "";
		}
		return line;
	}

Call this function using a FileLineReader object.
Hope this solves your problem

Have you written any filehandler?
Is your data saved as plain text (filename .txt) or as objects (filename .dat)?
Because you use different streams to read ".txt" or ".dat".

Is the data be to shown in a terminal whit System.out.print() or in an GUI or applet?

yes i wrote a program to handle files (filehandler)

and my data saved as plain text (in human readable format)

i dont want to show this data in terminal ..i want to open the file that content my data .It's a txt

You can use FileReader class under java.io package. Use read method to read the file.

to read a line at a time

public class FileLineReader extends FileReader {
    FileLineReader(File fileName) throws IOException {
    	super(fileName);
    }

String readLine() throws IOException{
		String line = "";
		int temp;
		while((temp=read())!='\n')
		{
			if(temp==-1)
				return line;  // End of file
			line+=(char)temp + "";
		}
		return line;
	}

Call this function using a FileLineReader object.
Hope this solves your problem

thanks for ur code ..but this program is to read data line by line rite?

what i want to do is to open a text file which contains human readable data (not binary)

new ProcessBuilder("notepad","a.txt").start(); where a.txt is the filename..and you can change notepad to any other program...like notepad++, wordpad depending on the editor u prefer

hope that helps

Here is another code snippet that might help:

BufferedReader reader = null;
try {
  reader = new BufferedReader(new FileReader("fileName"));
  String line = reader.readLine();
  while (line!=null) {
       // do whatever you want with line
      System.out.println(line);

     // this MUST be the last command:
    line = reader.readLine();
  }
} catch (IOException ioe) {
   System.out.println(ioe.getMessage());
} finally {
   try { if (reader!=null) reader.close();  } catch (Exception e) {}
}

yes i wrote a program to handle files (filehandler)

and my data saved as plain text (in human readable format)

i dont want to show this data in terminal ..i want to open the file that content my data .It's a txt

I was thinking about if you had built an applet or some GUI to show your text in, in a textfield for example, but it does not seem to be that way.
So I belive that solaheres answer will do the trick for you.

Good luck =)

new ProcessBuilder("notepad","a.txt").start(); where a.txt is the filename..and you can change notepad to any other program...like notepad++, wordpad depending on the editor u prefer

hope that helps

thank you soo much solahere this works properly .. :)

I was thinking about if you had built an applet or some GUI to show your text in, in a textfield for example, but it does not seem to be that way.
So I belive that solaheres answer will do the trick for you.

Good luck =)

yes it is.. thanks for ur code too

Member Avatar for harsh2327

yes i wrote a program to handle files (filehandler)

and my data saved as plain text (in human readable format)

i dont want to show this data in terminal ..i want to open the file that content my data .It's a txt

You can use FileReader class under java.io package. Use read method to read the file.

to read a line at a time

public class FileLineReader extends FileReader {
    FileLineReader(File fileName) throws IOException {
    	super(fileName);
    }

String readLine() throws IOException{
		String line = "";
		int temp;
		while((temp=read())!='\n')
		{
			if(temp==-1)
				return line;  // End of file
			line+=(char)temp + "";
		}
		return line;
	}

Call this function using a FileLineReader object.
Hope this solves your problem

------------------------------------------

Have you even tried implementing my code. What you understood is completely wrong. That code is meant for reading from "HUMAN READABLE FILES."

------------------------------------------

Have you even tried implementing my code. What you understood is completely wrong. That code is meant for reading from "HUMAN READABLE FILES."

hmm sorry i didnt implement ur code.. i just red it roughly ..but that previous code solved my problem .What i wanted 2 do is to open a txt file after i modified it with a filehandelling program

can you please tag this thread as solved!

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.