Win a copy of Head First Android this week in the Android forum!

alex cary

Greenhorn
+ Follow
since Feb 13, 2013
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by alex cary

I have a .java file and a .html file. I used the java I/O to input and output some data and now i have to somehow make it appear on the .html file.

How do i do that?

8 years ago
I do not know how to use them.
8 years ago
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?
8 years ago