Results 1 to 4 of 4
  1. #1

    Default Help FileHandling in Java


    What is ur name?
    how old r you?
    where do u live?

    the quest above is being save on notepad.txt .
    I want to put each one of them in a String array.
    example :
    String s[] = new String[3];
    s[1] = "what is ur name?";
    s[2] = "how old r you?";
    s[3] = "where do u live?";

    help me kong unsaon ni sya?

  2. #2

    Default Re: Help FileHandling in Java

    Is it saved exactly like that? Meaning, are each questions separated by newlines?

    Anyway, my Java skills are elementary at best. But maybe this would help.

    Code:
    import java.io.*;
    class FileRead 
    {
    	static String[] questions;
    	
    	public static void main(String args[])
    	{
    		try{
    		
    		// Open file
    		FileInputStream fstream = new FileInputStream("textfile.txt");
    		
    		// Get the object of DataInputStream
    		DataInputStream in = new DataInputStream(fstream);
    		BufferedReader br = new BufferedReader(new InputStreamReader(in));
    		String strLine;
    		int i = 0;
    		
    		//Read File Line By Line
    		while ((strLine = br.readLine()) != null){
    		
    			// Save each line in array
    			questions[i] = strLine;
    			i++;
    			
    		}
    		
    		//Close the input stream
    		in.close();
    		}catch (Exception e){
    		
    			//Catch exception if any
    			System.err.println("Error: " + e.getMessage());
    			
    		}
    		
    	}
    }
    This is from what I can remember about java from ~4? years ago. ^^
    I currently don't have a java compiler on this box so this is totally untested.

    At the very least, this script should contain the correct functions that would point you at the right direction.

    Good Luck.

    ps. I also remember seeing a java expert around here, somewhere. Maybe he can shed some light on this matter.

  3. #3

    Default Re: Help FileHandling in Java

    thanks
    it help me

  4. #4

    Default Re: Help FileHandling in Java

    Good to hear.

    Can you also post your working code, so that others who come by could also see the solution?

    Thanks.

  5.    Advertisement

Similar Threads

 
  1. Help in java
    By jairoh_ in forum Programming
    Replies: 12
    Last Post: 01-11-2012, 10:22 AM
  2. user defined class in java [help]
    By xianz87 in forum Programming
    Replies: 1
    Last Post: 07-06-2010, 07:53 PM
  3. Need help in JAVA plsss.. help 25problems..
    By FrozenBoi in forum Programming
    Replies: 89
    Last Post: 02-09-2010, 02:26 PM
  4. NEED HELP in JAVA EXCELAPI
    By rastaman81 in forum Programming
    Replies: 1
    Last Post: 05-11-2009, 09:17 PM
  5. need help in java programming: creating a folder
    By rastaman81 in forum Programming
    Replies: 4
    Last Post: 03-11-2009, 08:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top