Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Java Programming help needed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I was trying to make a website that uses a java program to read weather information from a file and then creates a web page.

Below is my entire code:

import java.io.*;
import java.util.Scanner;

public class P1 {

float max, min;

public static void main(String[] args) throws IOException {

// Open the file
// FileInputStream fstream = new FileInputStream("weather-short.csv");
//
// // Get the object of DataInputStream
// DataInputStream in = new DataInputStream(fstream);
// BufferedReader br = new BufferedReader(new InputStreamReader(in));
//
// String strLine;
// {
// // Read File Line By Line
// while ((strLine = br.readLine()) != null) {
// // Print the content on the console
// System.out.println(strLine);
// }
//
// // Close the input stream
// in.close();
//
// }

String input = readTextFile("");
System.out.println(input);
writeTextFile("", input);
String source = read("");
output(source);
split(input);
compare(input);
}

// Reading contents from the file

public static String readTextFile(String fileName) {
String Value = "";
FileReader file;
String line = "";
try {
file = new FileReader("weather-short.csv");
BufferedReader reader = new BufferedReader(file);
while ((line = reader.readLine()) != null) {
Value += line + "\n";
}

} catch (FileNotFoundException e) {
throw new RuntimeException("File not found");
} catch (IOException e) {
throw new RuntimeException("IO Error occured");
}
return Value;

}

// Writing contents to the new file

public static void writeTextFile(String fileName, String s) {
FileWriter output;
try {
output = new FileWriter("newfile.csv");
BufferedWriter writer = new BufferedWriter(output);
writer.write(s);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}

}

// Reading the Source.html file of Hello World

public static String read(String filename) {
String l = "";
String V = "";
try {
FileReader fn = new FileReader("Source.html");
BufferedReader reader = new BufferedReader(fn);
while ((l = reader.readLine()) != null) {
V += l + "\n";
}
} catch (FileNotFoundException e) {
throw new RuntimeException("File not found");
} catch (IOException e) {
throw new RuntimeException("IO Error occured");
}
return V;

}

// Writing to a new html file that contains the weather data

public static void output(String V) {
try {
FileWriter fstream = new FileWriter("out.html");
BufferedWriter out = new BufferedWriter(fstream);
out.write(V);
out.close();
} catch (IOException e) {
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
}
}

public static void split(String file) {
Scanner S1 = new Scanner(file);
S1.useDelimiter(",");
while (S1.hasNext()) {
System.out.print(S1.next());
System.out.println();

}

}
public static void compare(String F) {
for (int i = 0; i < F.length(); i++) {




}
}
}
}


The problems i am having are:
1. I need to keep track of the maximum and minimum temperature in the weather-short.csv file and compare it with the max or min global variables in the compare method, what is the way to do it?
2. How should I then link this code in the html file?
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please do not post the same question more than once.
    Bookmark Topic Watch Topic
  • New Topic