2016-02-27 63 views
1

我創建了10x10像素的gimp圖像: Image of my initials在Eclipse中編輯CSV文件

從這個我然後通過使用記事本++(我已經組織了10行:Image of my csv file opened with text editor in eclipse每列30位數字)從ppm轉換爲csv。

我的任務是創建一些代碼到eclipse中,使圖像更不混亂(意味着它將用空格替換逗號,在每三個數字後放置一個空格,並在每30個數字後創建一個新行)。

該任務的第二部分是向後工作。然後,我需要將新組織的創建的ppm文件轉換爲.xcf以在gimp中打開我的照片。它應該與上面的首字母相同。

我需要幫助的區域是在eclipse中。我需要寫什麼代碼才能讓我編輯這個.csv文件(我知道這是一個廣泛的問題,但任何提示或指針都會被讚賞)?我在哪裏可以將csv文件放在eclipse中(src,java project等)。如果你已經和我一起暴露了很長時間,那麼你對我表示感謝。我試圖儘可能簡化我的問題,這樣可以理解和解決。我會很感激任何幫助,因爲星期一我需要這樣做。謝謝!

〜艾哈邁德

回答

0

您可以在Eclipse IDE中使用Java做到這一點,

  1. 對於閱讀,你可以使用進口java.io.FileReader
  2. 對於由線你解析文件行的文件可以使用BufferedReader或 字符串[]

以下是啓動示例代碼。

public class SplitterExample 
{ 
    public static void main(String[] args) 
    { 
     //Input file which needs to be parsed 
     String fileToParse = "SampleCSVFile.csv"; 
     BufferedReader fileReader = null;    

    //Delimiter used in CSV file 
    final String DELIMITER = ","; 
    try 
    { 
     String line = ""; 
     //Create the file reader 
     fileReader = new BufferedReader(new FileReader(fileToParse)); 

     //Read the file line by line 
     while ((line = fileReader.readLine()) != null) 
     { 
      //Get all tokens available in line 
      String[] tokens = line.split(DELIMITER); 
      for(String token : tokens) 
      { 
       //Print all tokens 
       System.out.println(token); 
      } 
     } 
    } 
    catch (Exception e) { 
     e.printStackTrace(); 
    } 
    finally 
    { 
     try { 
      fileReader.close(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
} 

}

+0

非常感謝您的反饋!但是我能夠通過使用我的教授指南進行反覆試驗來完成作業。這就是我想出的:將正確的文件名(csv one)放入一個File對象,然後從那裏進行編輯。您的帖子也非常有幫助。謝謝! – xtremeslice