我正在尝试读取CSV文件并将其作为csv文件显示在Excel中

时间:2015-11-04 19:20:08

标签: java

***我有错误说明:

  

错误:在Main类中找不到主方法,请将主方法定义为:
  public static void main(String [] args)   我解决了上一个问题,但我现在收到此错误:C:\ Program Files \ Java \ jre1.8.0_60 \ bin \ javaw.exe(2015年11月8日,下午7:41:12)
  尝试运行此代码时:***       package filtermovingaverage;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

public class Main {
    //public static void main(String[] args){


    private static double freqS = 100;
    static ArrayList<Double> sec = null; 
    private static double[] pressure = new double[20481];

    void func() throws IOException
    {
        BufferedReader read = new BufferedReader(new FileReader(new File("C:\\Users\\KwakuK\\Downloads\\smith2.csv")));        
        String currentLine = new String();
        currentLine = read.readLine();
        int i = 0;
        //make some computation
        while((currentLine = read.readLine()) != null)
        {
            String[] numbers = currentLine.split(","); // split the string into sub strings
            if(numbers.length >= 3)
            {
                    System.out.println("currentLine: " + " " + currentLine);

                pressure[i++] = Double.parseDouble(numbers[2]); // when you do the 2, it's the third column which is the pressure
            }
        }
    }

    public static void setupFirstPlot() throws FileNotFoundException{
        sec = new ArrayList<Double>();
        double ws = 1/freqS;
        double n = (pressure.length)*ws;

        for(double i = 0; i < n; i = i + ws){ 
            sec.add(i);
        }
        PrintWriter pw = new PrintWriter(new File("plot13.csv"));
        for(int i = 0; i < pressure.length; i++){
            pw.write(sec.get(i)+","+pressure[i]+"\n");
        }
        pw.close();
    }

    public static void main(String[] args) throws FileNotFoundException{
        setupFirstPlot();
        System.out.println();
    }
}

1 个答案:

答案 0 :(得分:0)

尝试将package filtermovingaverage;添加到此java文件的顶部。