How to read text file?

Dear Everyone
I have coding below.
{color:#3366ff}*Text file scores.txt*
{color}1 1 1
2 2 2
*{color:#3366ff}Java class jtableone.class{color}*
import javax.swing.*;
public class jtableone extends JApplet {
public static void main(String[] args) throws Exception {
{color:#ff0000}//Read file scores.txt{color}
java.io.File file = new java.io.File("scores.txt");
Scanner input = new Scanner(file);
while (input.hasNext()){
String id = input.next();
String firstname = input.next();
String lastname = input.next();
{color:#ff0000}//System.out.println(id +" "+ firstname +" "+ lastname);
{color}}
input.close();
{color:#ff0000}//Crearte JTable{color}
private String[] columNames =
{"ID", "First Name", "Last Name"};
private Object[][] data = {
//{"12", "Tom", "Clark"},
//{"13", "helen", "Tan"}
{color:#ff0000}//Display JTable{color}
private JTable jTable1 = new JTable(data, columNames);
public jtableone(){
add(new JScrollPane(jTable1));
Can you tell me What i do next?
Create a Object[][] data which can read text file.
Thanks
sevenlon

sevenlon wrote:
Can you tell me What i do next?How are we supposed to know? We have no knowledge of what your assignment is.
Create a Object[][] data which can read text file.Then do that. Create the 2D array and store the data in it.
Also when posting code use code tags. Paste code, highlight it and click CODE button.

Similar Messages

  • How to read text file line by line...?

    how to read text file line by line, but the linefeed is defined by user, return list of string, each line of file is a item of list?
    please help me.
    Thanks very much

    Brynjar wrote:
    In Groovy, you would do something like:
    linefeed = "\n" //or "\r\n" if the user chose so
    lines = new File('pathtofile').text.split("${linefeed}")This is one of the things that has always annoyed me about Sun's sdk, i.e. the lack of easy ways to do things like that. You always end up making your own utilities or use something like Apache's commons.io. Same goes for jdbc and xml - I'll wait for appropriate topics to show how easy that is in Groovy :)I generally agree, but what I really don't like about the Groovy text-file handling niceties: They don't care about encoding/always use the default encoding. And as soon as you want to specify the encoding, it gets a lot more complex (granted, it's still easier than in Java).

  • Step by Step"How JSP read text file :

    Hi ,
    Any one know or have a good site to show step by step how JSP read text file.
    TQ.

    There is no difference Between reading a text file from JSP and reading a text file from Java.
    Just follow the same steps for JSP also.

  • How to read text file content in portal application?

    Hi,
    How do we read text file content in portal application?
    Can anyone forward the code to do do?
    Regards,
    Anagha

    Check the code below. This help you to know how to read the text file content line by line. You can display as you require.
    IUser user = WPUMFactory.getServiceUserFactory().getServiceUser("cmadmin_service");
    IResourceContext resourceContext = new ResourceContext(user);
    String filePath = "/documents/....";
    RID rid = RID.getRID(filePath);
    IResource resource = ResourceFactory.getInstance().getResource(rid,resourceContext);
    InputStream inputStream = resource.getContent().getInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
    String line = reader.readLine();
    while(line!=null) {
          line = reader.readLine();
         //You can append in string buffer to get file content as string object//
    Regards,
    Yoga

  • How to read text file contain chinese character ?

    Hi XI Expert,
    I have scenario to read text file contain Chinese Character using sender file adapter. but every i was check from sxmb_moni all the chinese character looks different. and also the target file also i has changes.
    Please advise me how to maintaine the chinese character in PI 7.0 SP17.
    Thank You and Best Regards
    Fernand

    Hi,
    Refer these threads..
    Receiver file adapter corrupting characters
    Problem in converting special characters in input text file
    Here is one more useful guide..
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/502991a2-45d9-2910-d99f-8aba5d79fb42
    Regards,
    Sarvesh
    Edited by: Sarvesh Singh on Nov 17, 2008 3:47 PM

  • How to read text file efficiently?

    I use CharBuffer to read text file:
    private List<String> load() throws IOException {
            final String B = "<BODY>";
            final String E = "</BODY>";
            List<String> docs = new ArrayList<String>();
            for (File file : files) {
                FileReader reader = new FileReader(file);
                CharBuffer buffer = CharBuffer.allocate(BSIZE);
                StringBuilder sb = new StringBuilder();
                while (reader.read(buffer) != -1) {
                    char[] dst = new char[buffer.length()];
                    buffer.get(dst);
                    sb.append(dst);
                    buffer.clear();
                String s = sb.toString();
                System.out.println(file + ": " + s.length());
                int start = 0;
                int i, j;
                while ((i = s.indexOf(B, start)) != -1) {
                    j = s.indexOf(E, i + B.length());
                    docs.add(s.substring(i + B.length(), j));
                    start = j + E.length();
                    //System.out.printf("%d %d %d%n", i, j, start);
            return docs;
        }The file size is 1324350, but the code say it is 772802.
    What's wrong with this code?
    I want to read text file as quickly as possible.
    Is this code the right way to read file?
    Should I use FileReader or nio Channel and ByteBuffer?
    Any suggestions are welcome!

    You are reading the file as if it were encoded in UTF-16. Each character uses two bytes so you have half the number of characters as you had bytes.
    The following code reads an entire file in one hit.
        public static String readText(File file) throws IOException {
            byte[] bytes = new byte[(int) file.length()];
            DataInputStream dis = new DataInputStream(new FileInputStream(file));
            try {
                dis.readFully(bytes);
            } finally {
                dis.close();
            return new String(bytes, "UTF-8"); // or whatever your file encoding is.
        }But you can still have less characters than bytes if there are any non ASCII-7 characters.

  • HI,,,How to read text file from my emulators root

    hi friends,
    Actully i m having problem with file connection i.e. i cant read text file from my root of the emulator.....
    i have tried like this...
    plz help me out
    String uri = "file:///C:/WTK22/appdb/DefaultColorPhone/filesystem/root1/New Folder/main.txt";
    InputConnection conn = (InputConnection)Connector.open( uri,Connector.READ );
    InputStream in = conn.openInputStream();
    conn.close();
         for(int j=0;j<12;j++)
         ch=in.read();
         str.append((char)ch);
    par1=str.toString();
    in.close();
         screen4.append(par1);
         display.setCurrent(screen4);

    still its not working.........
    String uri = "file:///C:/WTK22/appdb/DefaultColorPhone/filesystem/root1/readme.txt";
                        FileConnection conn = (FileConnection)Connector.open( uri,Connector.READ);
                        InputStream in = conn.openInputStream();
                        conn.close();
                   String ss="";
                   String str1="";     
                   int ch=0;
                   byte b[]=new byte[753];     
                             ch=in.read(b,0,753);
                             str1= new String(b,0,ch);
                                  ss=str1.substring(493,501);                     
                        screen4.append(ss);
                        display.setCurrent(screen4);
                        }catch(IOException io){}

  • How to read text file by clicking on text file ?

    Hello.. friends
    I have made a java editor. I want to pass file name to a function in application by clicking on particular text file.
    I assoiciated *.text file type with my application. when I click on text file application is run but I file is not read by my java application.
    For example : in windows System all text are oppened in notepad when we click on any text file.
    How to do this thing. please suggest me and if possible show me a sample code.
    Thanks

    If you are doing this in a web application you can set the content type appropriately and the file will open.
    If you are doing this standalone you can use the Java RunTime class and execute something like this as the command "notepad.exe c:\\myfile.txt" which should open it up on a Windows operating system.

  • How to read text file with big5 into db

    hi,
    how can i use UTL_FILE package to
    read a text file with big5 characters and insert into db?
    my oracle charset is AL32UTF8.
    thx a lot!

    Thx for yr answer!!!
    I have followed and it works.
    However, I got another problem with HKSCS. When the text file contained HKSCS, the store procedure also treats it as Big5 and when I select it out, the character was not the orginal one.
    Please suggest if you have any ideas.
    Many Thanks!!!

  • How to read Text file in WindowPhone 8.1

    I am unable to pick text file from SD card or from mobile in windowPhone 8.1 app but image file can pick easily using FileOpenPicker.
    below code working fine for image but when i changing PickerLocationId and Filter to "txt" or "doc " then not working. please do help.
    FileOpenPicker
    openPicker = new FileOpenPicker();
       openPicker.ViewMode = PickerViewMode.Thumbnail;
                openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                openPicker.FileTypeFilter.Add(".jpg");
                openPicker.FileTypeFilter.Add(".jpeg");
                openPicker.FileTypeFilter.Add(".png");
                openPicker.PickSingleFileAndContinue();

    Hi
    I guess you are in wrong picker location and should have fileType also added
    it should be documents lib
    https://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.pickers.pickerlocationid
    Regards
    Varun Ravindranath Please 'Mark as Answer' if my post answers your question and 'Vote as Helpful' if it helps you.

  • How to read text file and store in database

    Respected All,
    I have text file on my computer.
    I am using forms6i and oracle 9i.
    I want that when i press button then specifice world in text file is read and dispaly on form to be stored in database.
    Please provide some solution.
    Kind Regards

    Hello,
    Study the functions of the TEXT_IO() package
    http://www.oracle.com/webapps/online-help/forms/10g/state?navSetId=_&navId=3&vtTopicFile=f1_help/oraini/c_text_io.html&vtTopicId=
    Francois

  • How to read text file by using jfilechooser

    please check for me.. tbrowse is textfield, the file path n name are x dispaly at tBrowse. past is my class.
    public void actionPerformed( ActionEvent e )
    if (e.getSource() == btnBrowse)
    try
    FileReader in = null;
    if (Chooser.showOpenDialog(past.this)== JFileChooser.APPROVE_OPTION)
    File selectedFile = Chooser.getSelectedFile();
    in = new FileReader(selectedFile);
    tBrowse.setText(selectedFile.getPath());
    catch (IOException exception)
         System.out.println("Error processing file: " + exception);
    Message was edited by:
    fifa1509

    Does it compile? Does it do what you want when you run it?
    If you have a problem, say what that problem is (cut and paste any
    compiler error message).
    One small point is that you could actually print the stack trace as this
    will be much more informative if you have a problem.catch (IOException exception)
        exception.printStackTrace();
    }

  • Read text file in Flash

    How to read text file flash memory

    Use the 'more' command. Here is a console log showing it in use -
    VG202#dir flash:
    Directory of flash:/
    1 -rw- 18955952 Mar 1 2002 00:19:50 +00:00 vg20x-ipvoice-mz.124-22.T.
    bin
    128843776 bytes total (109887488 bytes free)
    VG202#copy run flash:Myconfig.txt
    Destination filename [Myconfig.txt]?
    1593 bytes copied in 0.392 secs (4064 bytes/sec)
    VG202#dir flash:
    Directory of flash:/
    2 -rw- 1593 Mar 6 2002 19:28:26 +00:00 Myconfig.txt
    1 -rw- 18955952 Mar 1 2002 00:19:50 +00:00 vg20x-ipvoice-mz.124-22.T.
    bin
    128843776 bytes total (109883392 bytes free)
    VG202#
    VG202#more flash:Myconfig.txt
    version 12.4
    no service pad
    service timestamps debug datetime msec
    service timestamps log datetime msec
    no service password-encryption
    hostname VG202
    boot-start-marker
    boot-end-marker
    logging message-counter syslog
    enable password cisco
    no aaa new-model
    ip source-route
    ip cef
    no ipv6 cef
    stcapp ccm-group 1
    stcapp
    stcapp feature access-code
    stcapp feature speed-dial
    stcapp call-control mode feature
    voice-card 0
    archive
    log config
    hidekeys
    interface FastEthernet0/0
    ip address 10.66.75.41 255.255.255.0
    duplex auto
    speed auto
    interface FastEthernet0/1
    no ip address
    shutdown
    duplex auto
    speed auto
    ip forward-protocol nd
    ip route 0.0.0.0 0.0.0.0 10.66.75.1
    no ip http server
    control-plane
    voice-port 0/0
    timeouts initial 60
    timeouts interdigit 60
    timeouts ringing infinity
    voice-port 0/1
    ccm-manager fax protocol cisco
    ccm-manager config server 10.66.90.130
    ccm-manager config
    ccm-manager sccp local FastEthernet0/0
    ccm-manager sccp
    mgcp fax t38 ecm
    sccp local FastEthernet0/0
    sccp ccm 10.66.75.212 identifier 2 version 6.0
    sccp ccm 10.66.75.211 identifier 1 version 6.0
    sccp
    sccp ccm group 1
    associate ccm 1 priority 1
    associate ccm 2 priority 2
    dial-peer voice 1 pots
    service stcapp
    port 0/0
    dial-peer voice 10 pots
    shutdown
    destination-pattern 10
    port 0/1
    dial-peer voice 11 pots
    shutdown
    destination-pattern 11
    port 0/0
    line con 0
    no modem enable
    line aux 0
    line vty 0 4
    password cisco
    login
    exception data-corruption buffer truncate
    end
    VG202#

  • How to read text in .kep files

    hey friends,
    how to read text in .kep files
    please help me .
    with regards,
    s.jagadeesh babu

    Hi,
    check this link:
    http://help.sap.com/saphelp_nw04s/helpdata/en/8f/42a293e35011d29b340000e8a4b41d/content.htm
    .kep files are SapShow Training Files. They can be played with sapshow.exe in Knowledge Warehouse.
    SAP Show is KW Viewer Application. You can use it to see “Kep” files. It can be run in windows without the SAP environment. To run SAP Show (4.6D version) you just need 3 files. First is SAP show executable file, another two are “Sapstg.dll” and “ZLib.dll”. You can easily find these files on internet.
    Regards,
    Niraj

  • How can I read text files from LAN if I only know the hostname?

    I'm new in Java Developing, and dont know the written classes yet. I need help, how to do the following steps?
    <p>1. How can I read text files from LAN if I only know the hostname, or IP address?
    <p>2. How to read lines from text files without read all lines from the beginning of file, just seek to a position.
    (ex. how can I read the 120th line?)
    <p>Please help!
    <p>sorry for the bad english

    I'm new in Java Developing, and dont know the written classes yet. I need help, how to do the following steps?
    1. How can I read text files from LAN if I only know the hostname, or IP address?You need to know the URL of the file. You need to know the hostname, port, protocl and relative path.
    The hostname is server, not file.
    2. How to read lines from text files without read all lines from the beginning of file, just seek to a position.Use the seek() to get to a random byte.
    (ex. how can I read the 120th line?)The only way to find the 120th line is to read the first 120 lines. You can use other file formats to find the 120th line without reading the whole file but to need to be able to detremine where the 120th line is

Maybe you are looking for