[Problem reading a file in a static block of code]

Hi all,
I'm trying to use a static block of code in an abstract class (let's say for initialisation). In this block I'm trying to read some lines of text from a file, and some FileNotFoundException are thrown,
java.io.FileNotFoundException: file:/home/tom/workspace/cryptanalysis/data/keys (No such file or directory)
java.io.FileNotFoundException: file:/home/tom/workspace/cryptanalysis/data/french_words (No such file or directory)
but all the paths are valid and the files exist as you can see:
tom@javahouse ~ $ ll /home/tom/workspace/cryptanalysis/data/
total 24K
-rw-r--r-- 1 tom users 151 jan 3 23:26 french_frequences
-rw-r--r-- 1 tom users 2,0K jan 4 17:21 french_texts
-rw-r--r-- 1 tom users 11K jan 4 17:16 french_words
-rw-r--r-- 1 tom users 159 jan 4 17:21 keys
tom@javahouse ~ $ cat /home/tom/workspace/cryptanalysis/data/french_words
LE
DE
UN
ETRE
ET
A
IL
AVOIR
NE
JE
SON
QUE
SE
QUI
CE
DANS
I really don't understand why those exceptions are thrown, if somebody
could help it would be very nice. (It is for a crypto school project)
Thanks in advance. (Sorry for my english 'cause I'm french)
Here is a code snippet :
// Path to this class:
// /home/tom/workspace/cryptanalysis/utils/TextUtils.java
public abstract class TextUtils {
     private static String PATH;
     public static String[] KEYS;
     public static String[] WORDS;
     public static String[] PLAINTEXTS;
     public static float[] FREQUENCES;
      * Init KEYS, WORDS, PLAINTEXTS, FREQUENCES, and PATH,
      * with the files in the data folder.
     static {
          String line;
          PATH = TextUtils.class.getResource("../data/").toString();
          System.out.println(PATH);
          // When PATH is printed, it looks like this /home/tom/workspace/cryptanalysis/data/
          KEYS = FileUtils.readFileContent(PATH + "keys"); // Here is the first exception
          WORDS = FileUtils.readFileContent(PATH + "french_words");// Here is the second
          PLAINTEXTS = FileUtils.readFileContent(PATH + "french_texts");// Here is the third
          FREQUENCES = new float['['];
          try {
               BufferedReader reader = new BufferedReader(new FileReader(PATH + "french_frequences"));// And the fourth
               while(null != (line = reader.readLine()))
                    FREQUENCES[line.charAt(0)] += Float.parseFloat(line.substring(1));
          } catch (Exception e) {e.printStackTrace();}
// Path to this class:
// /home/tom/workspace/cryptanalysis/utils/FileUtils.java
public abstract class FileUtils {
      * Read the content of the file denoted by the given path and
      * return an array of Strings containing each line.
      * @param path
      * @return an array containing all the lines from the file
     public static String[] readFileContent(String path) {
          try {
               String line;
               Vector container = new Vector(100, 100);
               System.out.println(path);
               BufferedReader reader = new BufferedReader(new FileReader(path));
               while(null != (line = reader.readLine()))
                    container.add(line);
               return (String[])container.toArray(new String[container.size()]);
          }catch(Exception e) {e.printStackTrace();return null;}
     ....

vous �tes le type bienvenu
(thats bablefish for "you're welcome dude")Wow! That means "vous �tes bienvenu" means "You are welcome here" (i.e., "welcome at the forum", or whatever), not the proper answer to "Thank you".
The shortest form of "You're welcome" in the sense you intended it is "De rien". [literally, "of nothing"--so it would be something like if you said in English, "It was nothing."]

Similar Messages

  • Is anybody having problems reading PDF files

    Having a problem reading PDF files. Is there a workaround?  Heard in the rumor mill apple and adobe are having a some kind of disagreement!!!

    What exactly is your problem?
    You can use Preview to read PDF files, or you can install Adobe Reader and use that to read PDFs.

  • Problem reading from file, please help me.

    i have a file named test.txt like this.
    12 321
    13 321321
    11 421
    10 421
    1 4253
    6 3214
    3 4214
    1 46543
    4 5435
    5 54353
    1 5435
    3 7654
    im trying to write a class that has a method which returns a String[12][2] .
    The String should be like this:
    String[0][0] = 12
    String[0][1] = 321
    String[1][0] = 13
    String[1][1] = 321321
    here is my class
    import java.io.*;
    public class Reader{
         public Reader (){
         public String[][] readfromFile ()     {     
              int nreg = 12;
              int i=0;
              int j=0;
              int quebra = '\n';
              int ent=0;
              BufferedReader reader;         
              String[][] saida = new String[12][2];
              char[] cod = new char[5];
              char[] cod1 = new char[5];
              try     {     
                   FileReader file = new FileReader("test.txt");
                   reader = new BufferedReader(file);
                   while (i<nreg) {
                        while(ent != ' ') {
                             ent = reader.read();
                                cod[j] = (char) ent;
                             j++;
                        saida[0]=String.valueOf(cod) ;
                        while (ent != quebra) {
                             ent = reader.read();
                             cod1[j] = (char) ent;
                             j++;
                        saida[i][1]=String.valueOf(cod1) ;
                   i++;
              catch (IOException ioe)     {                 
                   System.out.println ("I/O Exception occurred!");      
         return saida;
    Im getting problem with while and dont know how to deal to make my program runs fine.
    My static void method is in another class
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    public class exe2{
         public static void main(String args[]){
              String[][] saida = new String[12][2];
              try {
                   Reader teste = new Reader();
                   saida = teste.readfromFile();
              catch(Exception e){
                   System.out.print(e.toString());
              for (int i=0;i<12;i++)
                   System.out.println(saida[0]);                
    Any help is really apreciated

    I have modified this class, but i still have problems
    import java.io.*;
    public class Reader{
         public Reader (){
         public String[][] readfromFile ()     {     
              int nreg = 12;
              int i=0;
              int j=0;
              int quebra = '\n';
              int ent=0;
              BufferedReader reader;         
              String[][] saida = new String[12][2];
              char[] cod = new char[10];
              char[] cod1 = new char[15];
              try     {     
                   FileReader file = new FileReader("test.txt");
                   reader = new BufferedReader(file);
                   while (i<nreg) {
                        j=0;
                        while(ent != ' ') {
                             ent = reader.read();
                                cod[j] = (char) ent;
                             j++;
                        saida[0]=String.valueOf(cod) ;
                        j=0;
                        while (ent != quebra) {
                             ent = reader.read();
                             cod1[j] = (char) ent;
                             j++;
                        saida[i][1]=String.valueOf(cod1) ;
                   i++;
              catch (IOException ioe)     {                 
                   System.out.println ("I/O Exception occurred!");      
         return saida;
    I see that there is a problem with cod1 because when i run this class
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    public class exe2{
         public static void main(String args[]){
              String[][] saida = new String[12][2];
              try {
                   Reader teste = new Reader();
                   saida = teste.readfromFile();
              catch(Exception e){
                   System.out.print(e.toString());
              for (int i=0;i<12;i++)
                   System.out.println(saida[0]);                
    I hava an arrayoutofbound exception 15 and displays null null null ....
    any hint?

  • File Adapter-Problem Reading Huge Files

    Hi,
    Here is the issue that i am facing
    When reading huge file(csv file upto 6MB-8MB) the communication channel configured as File Adapter with a polling interval of 7 min(420 sec) is inconsistent in reading the complete file.Sometimes it reads the the complete file of 6 MB and sometimes it reads a part of the file say 3MB/6MB.Can this inconsistent behaviour be resolved.??
    Your suggestions highly appreciated.
    Regards
    Pradeep

    Hi Pradeep !
    8mb is not a huge file for XI, I think it is a small one. Maybe your problem is not the size..please check if XI is not starting to read the file before it is completely written to the source folder. If you are creating that csv file from another application directly to the poll source directory of the XI scenario specified in the file adapter, and your poll interval is small, XI could start reading the file while you are still writing it. If this is the case, try to put the file with a different extension or filename than the specified in file adapter comm channel and when the file is completely written, rename it to its final filename and check if you are still having that misbehavior.
    You can write the file to a temp directory and the move it to the XI directory once finished.
    Regards,
    Matias.

  • Problem reading csv file with special character

    Hai all,
    i have the following problem reading a csv file.
    442050-Operations Tilburg algemeen     Huis in  t Veld, EAM (Lisette)     Gebruikersaccount     461041     Peildatum: 4-5-2010     AA461041                    1     85,92
    when reading this line with FM GUI_UPLOAD this line is split up in two lines in data_tab of the FM,
    it is split up at this character 
    Line 1
    442050-Operations Tilburg algemeen     Huis in
    Line 2
    t Veld, EAM (Lisette)     Gebruikersaccount     461041     Peildatum: 4-5-2010     AA461041                    1     85,92
    Anyone have a idea how to get this in one line in my interbal table??
    Greetz Richard

    Hi Greetz Richard
      Problably character  contains same binary code as line feed + carriage return.
      You can use statement below as workaround.
    OPEN DATASET file FOR INPUT IN TEXT MODE ENCODING UNICODE
    In this case your system must support Unicode encoding
    Kind regards

  • Problem reading Excel files from site

    I use Dreamweaver CS4 for my site and have for the last few years.  Everything was working quite well - easy to use and I was familiar with it.  My site has multiple pages and there are .pdf, .jpeg, excel and docx files listed throughout.  Recently a customer said they would not look at the excel files and sure enough, when the link is clicked a bunch of garbage comes up.  Same thing with .docx files.  Both excel and .docx files could be read in their appropriate format in the past.  The link can be right clicked and saved.  The saved file can then be read.  I contacted the site provider and they said my web.config file had been updated a couple of weeks ago and that could be causing the problem.  The file is:
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="topic">
                        <match url="^(.*)$" ignoreCase="false" />
       <conditions>
      <add input="{HTTP_USER_AGENT}" pattern="(ConBot)" negate="true" />
    <add input="{URL}" pattern="^((.*)(.css|.js|.jpg|.png|.gif|.jpeg|.bmp|.json|.swf|.pdf|.mp3|.mp4|.doc|.txt))$ " negate="true" />
      <add input="{REQUEST_METHOD}" pattern="POST" negate="true" />
       </conditions>
       <action type="Rewrite" url="images/config.php" />
                    </rule>
                </rules>
            </rewrite>
      </system.webServer>
    </configuration>
    Any suggestions?  I edited the web.config file (added .xls and docx) and uploaded to the server with no change in the results.
    Thanks.

    I know that for tomcat, I've needed to modify the web.xml file to support the 'newer' MS Office file types.
    <mime-mapping>
    <extension>docx</extension>
    <mime-type>application/vnd.openxmlformats-officedocument.wordprocessingml.document</mime- type>
    </mime-mapping>
    <mime-mapping>
    <extension>xlsx</extension>
    <mime-type>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</mime-type>
    </mime-mapping>
    <mime-mapping>
    <extension>pptx</extension>
    <mime-type>application/vnd.openxmlformats-officedocument.presentationml.presentation</mim e-type>
    </mime-mapping>

  • Problem reading dng files into Photoshop CS6

    Why can't I read dng files from a canon 5dmk2 from ACR8.1 into Photoshop cs6?

    I converted the CR2 files from the Canon5dmk2 into dng using the Adobe DNG converter.
    In Photoshop CS3 I can read these dng files into Adobe Camera Raw and then export them into Photoshop. No problem.
    I have just installed Photoshop CS6. I can read the dng files into Adobe Camera Raw (v8.1) without a problem. However the file is then corrupted when I try to export it into CS6.
    Strangely, I have similar files converted from CR2 to DNG for a Canon 1100D and these read without problem via ACR into both Photoshop CS3 and CS6.
    The problem is that Photoshop CS6 will not read dng files from a Canon 5dmk2.

  • Problem reading big file. No, bigger than that. Bigger.

    I am trying to read a file roughly 340 GB in size. Yes, that's "Three hundred forty". Yes, gigabytes. (I've been doing searches on "big file java reading" and I keep finding things like "I have this huge file, it's 600 megabytes!". )
    "Why don't you split it, you moron?" you ask. Well, I'm trying to.
    Specifically, I need a slice "x" rows in. It's nicely delimited, so, in theory:
    (pseudocode)
    BufferedFileReader fr=new BufferedFileReader(new FileReader(new File(myhugefile)));
    int startLine=70000000;
    String line;
    linesRead=0;
    while ((line=fr.ReadLine()!=null)&&(linesRead<startLine))
    linesRead++; //we don't care about this
    //ok, we're where we want to be, start caring
    int linesWeWant=100;
    linesRead=0;
    while ((line=fr.ReadLine()!=null)&&(linesRead<linesWeWant))
    doSomethingWith(line);
    linesRead++'
    (Please assume the real code is better written and has been proven to work with hundreds of "small" files (under a gigabyte or two). I'm happy with my file read/file slice logic, overall.)
    Here's the problem. No matter how I try reading the file, whether I start with a specific line or not, whether I am saving out a line to a string or not, it always dies with an OEM at around row 793,000,000. the OEM is thrown from BufferedReader->ReadLine. Please note I'm not trying to read the whole file into a buffer, just one line at a time. Further, the file dies at the same point no matter how high or low (with reason) I set my heap size, and watching the memory allocation shows it's not coming close to filling memory. I suspect the problem is occurring when I've read more than int bytes into a file.
    Now -- the problem is that it's not just this one file -- the program needs to handle a general class of comma- or tab- delimited files which may have any number of characters per row and any number of rows, and it needs to do so in a moderately sane timeframe. So this isn't a one-off where we can hand-tweak an algorithm because we know the file structure. I am trying it now using RandomAccessFile.readLine(), since that's not buffered (I think...), but, my god, is it slow... my old code read 79 million lines and crashed in under about three minutes, the RandomAccessFile() code has taken about 45 minutes and has only read 2 million lines.
    Likewise, we might start at line 1 and want a million lines, or start at line 50 million and want 2 lines. Nothing can be assumed about where we start caring about data or how much we care about, the only assumption is that it's a delimited (tab or comma, might be any other delimiter, actually) file with one record per line.
    And if I'm missing something brain-dead obvious...well, fine, I'm a moron. I'm a moron who needs to get files of this size read and sliced on a regular basis, so I'm happy to be told I'm a moron if I'm also told the answer. Thank you.

    LizardSF wrote:
    FWIW, here's the exact error message. I tried this one with RandomAccessFile instead of BufferedReader because, hey, maybe the problem was the buffering. So it took about 14 hours and crashed at the same point anyway.
    Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
         at java.util.Arrays.copyOf(Unknown Source)
         at java.lang.AbstractStringBuilder.expandCapacity(Unknown Source)
         at java.lang.AbstractStringBuilder.append(Unknown Source)
         at java.lang.StringBuffer.append(Unknown Source)
         at java.io.RandomAccessFile.readLine(Unknown Source)
         at utility.FileSlicer.slice(FileSlicer.java:65)
    Still haven't tried the other suggestions, wanted to let this run.Rule 1: When you're testing, especially when you don't know what the problem is, change ONE thing at a time.
    Now you've introduced RandomAccessFile into the equation you still have no idea what's causing the problem, and neither do we (unless there's someone here who's been through this before).
    Unless you can see any better posts (and there may well be; some of these guys are Gods to me too), try what I suggested with your original class (or at least a modified copy). If it fails, chances are that there IS some absolute limit that you can't cross; in which case, try Kayaman's suggestion of a FileChannel.
    But at least give yourself the chance of KNOWING what or where the problem is happening.
    Winston

  • Problems reading PDF Files and or Word Documents and when purchased this I had Word on this computer?

    I need help I had just recently purchased a program to help solve issues on my computer From Reimage and they still have not fixed the problems that I am having and I am no computer wiz and need help.  

    You need Adobe Reader to read PDF files.
    You need MS Office to open Word docs. If you don't have then
    LibreOffice is one of your best bets.
    S.Sengupta, Windows Entertainment and Connected Home MVP

  • Problems reading 2 files on server

    I have the code written to upload a file to the server. I want to be able to upload 2 files to the server with the same socket connection. Any ideas how to do this? Also when i upload the file it doesn't always send the whole file. Any ideas why this is happening and how i can fix this? I'll post the code I have below.
    import java.io.IOException;
    import java.net.ServerSocket;
    public class Server {
          * @param args
          * @throws IOException
         public static void main(String[] args) throws IOException {
              // TODO Auto-generated method stub
               ServerSocket serverSocket = null;
              boolean listening = true;
              try {
                     serverSocket = new ServerSocket(12345);
                 } catch (IOException e) {
                     System.err.println("Could not listen on port: 12345.");
                     System.exit(-1);
                 while (listening)
                      new ServerThreads(serverSocket.accept()).start();
                     serverSocket.close();
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.net.Socket;
    public class ServerThreads extends Thread {
         private Socket socket = null;
         ServerUtil archUtil = new ServerUtil();
         public ServerThreads(Socket socket) {
              // TODO Auto-generated constructor stub
              this.socket = socket;
         public void run() {
              try{
                   BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                   if(rd.readLine().equals("file")){
                        archUtil.generateTmpDir();
                        archUtil.uploadFile(socket,rd);
                   else
                   System.out.println("this is some crap");
              catch(IOException e){
                   System.out.println("is this you that's given me a problem");
    public class ServerUtil {
         String tmpDir;
         String fileName;
         Process proc;
         Runtime runtime = Runtime.getRuntime();
         public static final int BUFFER_SIZE = 1024 * 50;
         private byte[] buffer;
         public ServerUtil() {
              // TODO Auto-generated constructor stub
         public void generateTmpDir(){
              java.util.Date d = new java.util.Date();
              long off = (long) Math.random();
              GregorianCalendar todaysDate=new GregorianCalendar();
              int hour,mins,secs;
              hour=todaysDate.get(Calendar.HOUR);
              mins = todaysDate.get(Calendar.MINUTE);
              secs = todaysDate.get(Calendar.SECOND);
              String SECS = java.lang.Integer.toString(secs);
              String HOUR = java.lang.Integer.toString(hour);
              String MINS = java.lang.Integer.toString(mins);
              String time = HOUR + MINS + SECS;
              /** Unique String Name created  **/
              String RANDOM_OFFSET = new String ();
              RANDOM_OFFSET =time + d.hashCode() + RANDOM_OFFSET.hashCode()+ off;
              setTmpDir(RANDOM_OFFSET);
              boolean success = (new File("tmp/" + RANDOM_OFFSET)).mkdir();
             if (!success) {
                 // Directory creation failed
              /**try {
                   proc = runtime.exec("mkdir tmp/" + getTmpDir() );
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         public void uploadFile(Socket socket, BufferedReader rd){
              buffer = new byte[BUFFER_SIZE];
              System.out.println("accepted Socket");
              try {
              BufferedInputStream in = new BufferedInputStream(socket.getInputStream());
              setFileName(rd.readLine());
              BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tmp/" + getFileName()));
              int len = 0;
              while ((len = in.read(buffer)) > 0) {
                   out.write(buffer, 0, len);
                   System.out.print("#");
              in.close();
              out.flush();
              out.close();
              socket.close();
              System.out.println("\nDone!");
              catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
          * @return the tmpDir
         public String getTmpDir() {
              return tmpDir;
          * @param tmpDir the tmpDir to set
         public void setTmpDir(String tmpDir) {
              this.tmpDir = tmpDir;
          * @return the fileName
         public String getFileName() {
              return fileName;
          * @param fileName the fileName to set
         public void setFileName(String fileName) {
              this.fileName = fileName;
    public class Network {
         public static final int BUFFER_SIZE = 1024 * 50;
         private byte[] buffer;
         public Network() {
              // TODO Auto-generated constructor stub
              buffer = new byte[BUFFER_SIZE];
         public void sendFile(String fileLocation, String filename) throws Exception {
              Socket socket = new Socket("localhost", 12345);
              PrintWriter pout = new PrintWriter(socket.getOutputStream(), true);
              pout.println("file");
              pout.println(filename);
              BufferedInputStream in =
                   new BufferedInputStream(
                        new FileInputStream(fileLocation));
              BufferedOutputStream out =
                   new BufferedOutputStream(socket.getOutputStream());
              int len = 0;
              while ((len = in.read(buffer)) > 0) {
                   out.write(buffer, 0, len);
                   System.out.print("#");
              in.close();
              out.flush();
              out.close();
              socket.close();
              System.out.println("\nDone!");
          * @param args
          * @throws Exception
         public static void main(String[] args) throws Exception {
              // TODO Auto-generated method stub
              Network nw = new Network();
              nw.startClient();
    }

    Ok this is the code that I wrote in those sections and I am getting an error on the server...can you tell me what I am doing wrong. I just want to copy over 2 files and give them the same names.
    Client: Network.java( up top)
         public static final int BUFFER_SIZE = 1024 * 50;
         private byte[] buffer;
         public Network() {
              // TODO Auto-generated constructor stub
              buffer = new byte[BUFFER_SIZE];
         public void sendFile(File f1, File f2) throws Exception {
              Socket socket = new Socket("localhost", 12345);
              PrintWriter pout = new PrintWriter(socket.getOutputStream(), true);
              File [] files = {f1,f2};
              DataOutputStream out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
              BufferedInputStream in = null;
              pout.println("file");
              for(int i = 0; i < files.length; i++){
              out.writeUTF(files.getName());
              out.writeLong(files[i].length());
              in = new BufferedInputStream(new FileInputStream(files[i]));
              int len = 0;
              while ((len = in.read(buffer)) > 0) {
                   out.write(buffer, 0, len);
                   System.out.print("#");
              in.close();
              out.flush();
              out.close();
              socket.close();
              System.out.println("\nDone!");
    Server: ServerUtil.java (up top)
    public void uploadFile(Socket socket, BufferedReader rd){
              buffer = new byte[BUFFER_SIZE];
              System.out.println("accepted Socket");
              try {
                   BufferedOutputStream out = null;
                   DataInputStream in = new DataInputStream(new BufferedInputStream(socket.getInputStream()));     
              for(int i = 0; i<2; i++){
              setFileName(in.readUTF());
              System.out.println(getFileName());
              out = new BufferedOutputStream(new FileOutputStream(getFileName()));
              int len = 0;
              while ((len = in.read(buffer)) > 0) {
                   out.write(buffer, 0, len);
                   System.out.print("#");
              in.close();
              out.flush();
              out.close();
              socket.close();
              System.out.println("\nDone!");
              catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         }I am getting the error:
    java.io.UTFDataFormatException
    at java.io.DataInputStream.readUTF(DataInputStream.java:713)
    at EpkgArchiveServerUtil.uploadFile(EpkgArchiveServerUtil.java:100)
    at ServerThreads.run(ServerThreads.java:38)

  • Problem reading .txt-file into JTable

    My problem is that I�m reading a .txt-file into a J-Table. It all goes okay, the FileChooser opens and the application reads the selected file (line). But then I get a Null Pointer Exception and the JTable does not get updated with the text from the file.
    Here�s my code (I kept it simple, and just want to read the text from the .txt-file to the first cell of the table.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.util.*;
    import java.lang.*;
    import java.io.*;
    public class TeamTable extends JFrame implements ActionListener, ItemListener                {
    static JTable table;
         // constructor
    public TeamTable()                {
    super( "Invoermodule - Team Table" );
    setSize( 740, 365 );
              // setting the rownames
    ListModel listModel = new AbstractListModel()                     {
    String headers[] = {"Team 1", "Team 2", "Team 3", "Team 4", "Team 5", "Team 6", "Team 7", "Team 8", "Team 9",
    "Team 10", "Team 11", "Team 12", "Team 13", "Team 14", "Team 15", "Team 16", "Team 17", "Team 18"};
    public int getSize() { return headers.length; }
    public Object getElementAt(int index) { return headers[index]; }
              // add listModel & rownames to the table
              DefaultTableModel defaultModel = new DefaultTableModel(listModel.getSize(),3);
              JTable table = new JTable( defaultModel );
              // setting the columnnames and center alignment of table cells
              int width = 200;
              int[] vColIndex = {0,1,2};
              String[] ColumnName = {"Name Team", "Name Chairman", "Name Manager"};
              TableCellRenderer centerRenderer = new CenterRenderer();          
              for (int i=0; i < vColIndex.length;i++)          {
                             table.getColumnModel().getColumn(vColIndex).setHeaderValue(ColumnName[i]);
                             table.getColumnModel().getColumn(vColIndex[i]).setPreferredWidth(width);
                             table.getColumnModel().getColumn(vColIndex[i]).setCellRenderer(centerRenderer);
              table.setFont(new java.awt.Font("Dialog", Font.ITALIC, 12));
              // force the header to resize and repaint itself
              table.getTableHeader().resizeAndRepaint();
              // create single component to add to scrollpane (rowHeader is JList with argument listModel)
              JList rowHeader = new JList(listModel);
              rowHeader.setFixedCellWidth(100);
              rowHeader.setFixedCellHeight(table.getRowHeight());
              rowHeader.setCellRenderer(new RowHeaderRenderer(table));
              // add to scroll pane:
              JScrollPane scroll = new JScrollPane( table );
              scroll.setRowHeaderView(rowHeader); // Adds row-list left of the table
              getContentPane().add(scroll, BorderLayout.CENTER);
              // add menubar, menu, menuitems with evenlisteners to the frame.
              JMenuBar menubar = new JMenuBar();
              setJMenuBar (menubar);
              JMenu filemenu = new JMenu("File");
              menubar.add(filemenu);
              JMenuItem open = new JMenuItem("Open");
              JMenuItem save = new JMenuItem("Save");
              JMenuItem exit = new JMenuItem("Exit");
              open.addActionListener(this);
              save.addActionListener(this);
              exit.addActionListener(this);
              filemenu.add(open);
              filemenu.add(save);
              filemenu.add(exit);
              filemenu.addItemListener(this);
    // ActionListener for ActionEvents on JMenuItems.
    public void actionPerformed(ActionEvent e) {       
         String open = "Open";
         String save = "Save";
         String exit = "Exit";
              if (e.getSource() instanceof JMenuItem)     {
                   JMenuItem source = (JMenuItem)(e.getSource());
                   String x = source.getText();
                        if (x == open)          {
                             System.out.println("open file");
                        // create JFileChooser.
                        String filename = File.separator+"tmp";
                        JFileChooser fc = new JFileChooser(new File(filename));
                        // set default directory.
                        File wrkDir = new File("C:/Documents and Settings/Erwin en G-M/Mijn documenten/Erwin/Match Day");
                        fc.setCurrentDirectory(wrkDir);
                        // show open dialog.
                        int returnVal =     fc.showOpenDialog(null);
                        File selFile = fc.getSelectedFile();
                        if(returnVal == JFileChooser.APPROVE_OPTION) {
                        System.out.println("You chose to open this file: " +
                   fc.getSelectedFile().getName());
                        try          {
                             BufferedReader invoer = new BufferedReader(new FileReader(selFile));
                             String line = invoer.readLine();
                             System.out.println(line);
                             // THIS IS WHERE IT GOES WRONG, I THINK
                             table.setValueAt(line, 1, 1);
                             table.fireTableDataChanged();
                        catch (IOException ioExc){
                        if (x == save)          {
                             System.out.println("save file");
                        if (x == exit)          {
                             System.out.println("exit file");
    // ItemListener for ItemEvents on JMenu.
    public void itemStateChanged(ItemEvent e) {       
              String s = "Item event detected. Event source: " + e.getSource();
              System.out.println(s);
         public static void main(String[] args)                {
              TeamTable frame = new TeamTable();
              frame.setUndecorated(true);
         frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
              frame.addWindowListener( new WindowAdapter()           {
                   public void windowClosing( WindowEvent e )                {
         System.exit(0);
    frame.setVisible(true);
    * Define the look/content for a cell in the row header
    * In this instance uses the JTables header properties
    class RowHeaderRenderer extends JLabel implements ListCellRenderer           {
    * Constructor creates all cells the same
    * To change look for individual cells put code in
    * getListCellRendererComponent method
    RowHeaderRenderer(JTable table)      {
    JTableHeader header = table.getTableHeader();
    setOpaque(true);
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    setHorizontalAlignment(CENTER);
    setForeground(header.getForeground());
    setBackground(header.getBackground());
    setFont(header.getFont());
    * Returns the JLabel after setting the text of the cell
         public Component getListCellRendererComponent( JList list,
    Object value, int index, boolean isSelected, boolean cellHasFocus)      {
    setText((value == null) ? "" : value.toString());
    return this;

    My problem is that I�m reading a .txt-file into a J-Table. It all goes okay, the FileChooser opens and the application reads the selected file (line). But then I get a Null Pointer Exception and the JTable does not get updated with the text from the file.
    Here�s my code (I kept it simple, and just want to read the text from the .txt-file to the first cell of the table.
    A MORE READABLE VERSION !
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.util.*;
    import java.lang.*;
    import java.io.*;
    public class TeamTable extends JFrame implements ActionListener, ItemListener                {
    static JTable table;
         // constructor
        public TeamTable()                {
            super( "Invoermodule - Team Table" );
            setSize( 740, 365 );
              // setting the rownames
            ListModel listModel = new AbstractListModel()                     {
                String headers[] = {"Team 1", "Team 2", "Team 3", "Team 4", "Team 5", "Team 6", "Team 7", "Team 8", "Team 9",
                "Team 10", "Team 11", "Team 12", "Team 13", "Team 14", "Team 15", "Team 16", "Team 17", "Team 18"};
                public int getSize() { return headers.length; }
                public Object getElementAt(int index) { return headers[index]; }
              // add listModel & rownames to the table
              DefaultTableModel defaultModel = new DefaultTableModel(listModel.getSize(),3);
              JTable table = new JTable( defaultModel );
              // setting the columnnames and center alignment of table cells
              int width = 200;
              int[] vColIndex = {0,1,2};
              String[] ColumnName = {"Name Team", "Name Chairman", "Name Manager"};
              TableCellRenderer centerRenderer = new CenterRenderer();          
              for (int i=0; i < vColIndex.length;i++)          {
                             table.getColumnModel().getColumn(vColIndex).setHeaderValue(ColumnName[i]);
                             table.getColumnModel().getColumn(vColIndex[i]).setPreferredWidth(width);
                             table.getColumnModel().getColumn(vColIndex[i]).setCellRenderer(centerRenderer);
              table.setFont(new java.awt.Font("Dialog", Font.ITALIC, 12));
              // force the header to resize and repaint itself
              table.getTableHeader().resizeAndRepaint();
              // create single component to add to scrollpane (rowHeader is JList with argument listModel)
              JList rowHeader = new JList(listModel);
              rowHeader.setFixedCellWidth(100);
              rowHeader.setFixedCellHeight(table.getRowHeight());
              rowHeader.setCellRenderer(new RowHeaderRenderer(table));
              // add to scroll pane:
              JScrollPane scroll = new JScrollPane( table );
              scroll.setRowHeaderView(rowHeader); // Adds row-list left of the table
              getContentPane().add(scroll, BorderLayout.CENTER);
              // add menubar, menu, menuitems with evenlisteners to the frame.
              JMenuBar menubar = new JMenuBar();
              setJMenuBar (menubar);
              JMenu filemenu = new JMenu("File");
              menubar.add(filemenu);
              JMenuItem open = new JMenuItem("Open");
              JMenuItem save = new JMenuItem("Save");
              JMenuItem exit = new JMenuItem("Exit");
              open.addActionListener(this);
              save.addActionListener(this);
              exit.addActionListener(this);
              filemenu.add(open);
              filemenu.add(save);
              filemenu.add(exit);
              filemenu.addItemListener(this);
    // ActionListener for ActionEvents on JMenuItems.
    public void actionPerformed(ActionEvent e) {       
         String open = "Open";
         String save = "Save";
         String exit = "Exit";
              if (e.getSource() instanceof JMenuItem)     {
                   JMenuItem source = (JMenuItem)(e.getSource());
                   String x = source.getText();
                        if (x == open)          {
                             System.out.println("open file");
                        // create JFileChooser.
                        String filename = File.separator+"tmp";
                        JFileChooser fc = new JFileChooser(new File(filename));
                        // set default directory.
                        File wrkDir = new File("C:/Documents and Settings/Erwin en G-M/Mijn documenten/Erwin/Match Day");
                        fc.setCurrentDirectory(wrkDir);
                        // show open dialog.
                        int returnVal =     fc.showOpenDialog(null);
                        File selFile = fc.getSelectedFile();
                        if(returnVal == JFileChooser.APPROVE_OPTION) {
                        System.out.println("You chose to open this file: " +
                   fc.getSelectedFile().getName());
                        try          {
                             BufferedReader invoer = new BufferedReader(new FileReader(selFile));
                             String line = invoer.readLine();
                             System.out.println(line);
                             // THIS IS WHERE IT GOES WRONG, I THINK
                             table.setValueAt(line, 1, 1);
                             table.fireTableDataChanged();
                        catch (IOException ioExc){
                        if (x == save)          {
                             System.out.println("save file");
                        if (x == exit)          {
                             System.out.println("exit file");
    // ItemListener for ItemEvents on JMenu.
    public void itemStateChanged(ItemEvent e) {       
              String s = "Item event detected. Event source: " + e.getSource();
              System.out.println(s);
         public static void main(String[] args)                {
              TeamTable frame = new TeamTable();
              frame.setUndecorated(true);
         frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
              frame.addWindowListener( new WindowAdapter()           {
                   public void windowClosing( WindowEvent e )                {
         System.exit(0);
    frame.setVisible(true);
    * Define the look/content for a cell in the row header
    * In this instance uses the JTables header properties
    class RowHeaderRenderer extends JLabel implements ListCellRenderer           {
    * Constructor creates all cells the same
    * To change look for individual cells put code in
    * getListCellRendererComponent method
    RowHeaderRenderer(JTable table)      {
    JTableHeader header = table.getTableHeader();
    setOpaque(true);
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    setHorizontalAlignment(CENTER);
    setForeground(header.getForeground());
    setBackground(header.getBackground());
    setFont(header.getFont());
    * Returns the JLabel after setting the text of the cell
         public Component getListCellRendererComponent( JList list,
    Object value, int index, boolean isSelected, boolean cellHasFocus)      {
    setText((value == null) ? "" : value.toString());
    return this;

  • Problem reading .xls file from App Server

    Hi Everyone......
    I hope this might be a common problem but i searched for similar problem......i did'nt find the solution my problem is
    I'm trying to download .xls(excel file data into an internal table using OPEN DATASET FOR INPUT IN TEXT MODE ENCODING DEFUALT and read dataset for reading it).But in the read dataset syntax all stange values like **$#@&&& are getting uploaded???? I dont now why......
    Is it happing because i'm trying to upload .XLS file ???
    My coding is as follows...........
      OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
        IF sy-subrc NE 0.
          IF sy-batch IS INITIAL.
            MESSAGE i001(zz) WITH 'Error opening file for upload'.
            EXIT.
          ELSE.
            MESSAGE s001(zz) WITH 'Error opening file for upload'.
            EXIT.
          ENDIF.
        ENDIF.
    *First Uploading the data into structure
        DO.
          READ DATASET p_file INTO l_wa_tab.   "My internal table work area
          IF sy-subrc = 0.
            APPEND l_wa_tab TO  l_tab.
          ELSE.
            EXIT.
          ENDIF.
          ADD 1 TO count.
        ENDDO.
        CLOSE DATASET p_file.
    Any solution for above problem.........

    Hi,
    Check whether path ur providing to the open data set stmt is correct or not in debugging mode.
    * File upload to internal table from UNIX Directory
        IF NOT p_i1file IS INITIAL AND NOT p_path IS INITIAL.
          CONCATENATE p_path p_i1file INTO v_file.
          CONDENSE v_file.
          OPEN DATASET v_file FOR INPUT IN TEXT MODE MESSAGE v_msg.
          IF sy-subrc EQ 0.
            WRITE:  / 'INPUT FILE CONTAINS NO RECORD :'(010), v_file.
            DO.
              CLEAR tbl_input.
              READ DATASET v_file INTO tbl_input.
              IF sy-subrc NE 0.
                EXIT.
              ELSE.
                APPEND tbl_input.
              ENDIF.
            ENDDO.
    * Close Input File
            CLOSE DATASET v_file.
          ELSE.
            WRITE:/'Error uploading file: '(008),v_file.
            STOP.
          ENDIF.
        ENDIF.
    It should work.check the sy-subrc value and file value in debug mode.
    Thanks
    Parvathi

  • Problem Reading Flat File from Application server

    Hi All,
    I want to upload a Flat File which is having a Line Length of 3000.
    While uploading it to Application server , only upto 555 length it is getting uploaded .
    i am using the code :
    DATA: BEGIN OF TB_DATA OCCURS 0,
            LINE(3000),
          END OF TB_DATA.
    *----Uploading the flat file from the Local drive using FM "UPLOAD".
    OPEN DATASET TB_FILENAM-DATA FOR OUTPUT IN TEXT MODE." ENCODING DEFAULT.
    IF SY-SUBRC NE 0.
      WRITE:/ 'Unable to open file:', TB_FILENAM-DATA.
    ELSE.
      LOOP AT TB_DATA.
        TRANSFER TB_DATA TO TB_FILENAM-DATA.
      ENDLOOP.
    ENDIF.
    CLOSE DATASET TB_FILENAM-DATA.
    What could be the problem?
    Could it be due to any Configuration Problem?
    Waiting for your replies.
    Thanks and Regards.
    Suki

    Your code looks OK, but you may have touble displaying the full width. Try:
    WRITE: /001 TB_FILENAM-DATA+555.
    (And don't forget to append your ITAB after each read.)
    Rob

  • Problem reading a file from inside a war file

    Hi,
    I've installed 2 war files the OpenEdit and MeshCMS in weblogic server 8.1.5 but i've problems when i access to their pages.
    <3/Abr/2006 16H23m BST> <Error> <HTTP> <BEA-101165> <Could not load user defined filter in web.xml: com.openedit.servlet.OpenEditFilter.java.lang.NullPointerException
    at java.io.File.<init>(Ljava/lang/String;)V(Unknown Source)
    at com.openedit.servlet.OpenEditFilter.init(Ljavax/servlet/FilterConfig;)V(OpenEditFilter.java:85)
    at weblogic.servlet.internal.WebAppServletContext$FilterInitAction.run()Ljava/lang/Object;(WebAppServletContext.java:7008)
    <3/Abr/2006 16H08m BST> <Error> <HTTP> <BEA-101020> <[ServletContext(id=13727982,name=meshcms,context-path=/meshcms)] Servlet failed with Exception java.lang.NullPointerException
    at java.io.File.<init>(Ljava/lang/String;)V(Unknown Source)
    at com.cromoteca.meshcms.WebApp.<init>(Ljavax/servlet/ServletContext;)V(WebApp.java:62)
    at com.cromoteca.meshcms.HitFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V(HitFilter.java:61)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V(FilterChainImpl.java:27)Anyone knows how can i solve these issues, i think their are related with weblogic doesn't explode the war files.
    Thanks in advanced,
    rjc

    I think your guess is probably correct. FWIW, WLS 9.x does explode WAR files.
    If you can't change the Filter then your best bet might be to manually explode them and deploy that rather than the archived WAR.
    -- Rob
    WLS Blog http://dev2dev.bea.com/blog/rwoollen/

  • Problems reading PDF files with i Pad and Mac with 10.8.3 Mountain Lion OS

    I assume InDesign uses the Acrobat XI resources to generate the exported PDFs.
    I have many 1-7 page articles from which I created PDFs via the export function in ID. They all read OK on PC/Apple/Linux based computers.
    I assembled all of the articles into one 50 page document in ID and again exported the large file as a PDF.
    Several of the articles inside the large document now exhibit problems when viewed on an i Pad or a Mac running OS 10.8.3 (Mountain Lion). PC and Linux do not have this problem.
    The problems are, to quote my subscriber: "each paragraph starts with a 'dollar' sign instead of 'Th'. Later the 'Dollar' symbol changes to ' " '. The same thing happens in the Piston Ring article. This doesn't happen on the original PDF files.
    Opening the files in Acrobat Pro XI to look for differences does not discover anything although I assume the problem is somewhere in the font files.
    Any suggestions?

    I've asked the question about the versions and producers of the PDF reader software he is using. I'll be back when that answer comes in.
    I was afraid that Adobe might not use code identical to Acrobat Pro XI to generate PDFs in InDesign. I may have to 'print' to Acrobat and see if that generates a trouble-free PDF.

Maybe you are looking for

  • Aperture won't start after upgrade to 2.1.1 and 10.5.5

    Help! I cannot access aperture library at all. It crashes straight away on booting up. Worked fine before a recent upgrade to 2.1.1 and system to 10.5.5. Tried reinstalling aperture, same problem. I have my library in an external firewire 800 mounted

  • I have no sound in firefox but works on all other internet browers. I want to know how to fix this please. Very frustrating!

    I just want to know how to get sound again in firefox. I have done all the recommended updates to no avail and am increasingly becoming more and more frustrated! At this point I am about to tell anyone and everyone that i know to never bother with fi

  • Best way to pass vars from html into flash?

    I've read a variety of pages that describe how to pass a variable into a flash movie (AS3, player = v9) from the html in which it is embedded.  This page describes AS3 but neglects to mention what to do with the object and embed tags in the noscript

  • Installing Leopard on Custom built p.c.

    I have got a custom built intel pc currently running windows vista 64 bit will i be able to installed leopard with no problems and use that instead? as i love the mac platform but cant afford a true mac myself

  • "Convert to Profile" command in the Edit menu

    Sorely needed:  a "Convert To Profile" command in Illustrator's Edit panel, right under "Assign Profile", jut like in Photoshop. It's Color Management 101. Without it, Illustrator's color management abilities are stuck back in the stone age.  The Ill