Java writing to files
is there a limit to how much words you could write into a file? or is my computer just buggy? i was trying to write a three dimensional array in a file using java (of course!) and it looks like it could only write around 40% of it. The size of each dimension is 12.
any suggestions guys? or comments? thank you very much.
Be sure java can write up to 1Gb without much problems, although you probably will run into some troubles with more than 2Gb. Anyway 99% is that you code is just buggy, so post significant parts of it enclosed in code tags (see http://forum.java.sun.com/help.jspa?sec=formatting ).
Similar Messages
-
Error in writing to file '$ORACLE_HOME/jdk/jre/bin/java'
Hi,
I have installed Forms & Reports Services Standalone (10.1.2.0.2) on RHEL 5 and now I am applying the Oracle Application Server 10g Release 2, Patch Set 3 (10.1.2.3), but OUI gives the following error:
Error in writing to file '$ORACLE_HOME/jdk/jre/bin/java'.
[$ORACLE_HOME/jdk/jre/bin/java
(Text file busy)]
I can't seem to find anything about this error on metalink or via google. Can anyone help me solve this? Thanks.Ok, this time I stopped all processes first with opmnctl stopall and emctl stop iasconsole. I then started OUI again to install the patch. It seemed to go fine - i didnt get that java error this time, but another error almost at the end of the installation:
Error in invoking target 'proxy_install runm_install server_install cgi_install
cli_install conv_install qv_install' of makefile
'/opt/oracle/Forms10gR2/reports/lib/ins_reports.mk'
According to Metalink ID 564174.1 - "Any installation of Oracle Application Server 10g Release 2 (10.1.2.0.2) on OEL 5.x or RHEL 5.x in which Reports is getting installed will fail with reports relinking errors" and the solution is as follows:
# rpm -i xorg-x11-libs-compat-6.8.2-1.EL.33.0.1.i386.rpm
# mv /usr/lib/libXtst.so.6 /usr/lib/libXtst.so.6.ORG
# ln -s /usr/X11R6/lib/libXtst.so.6 /usr/lib/libXtst.so.6
I have already done these 3 steps before the base installation (just to avoid this error), yet I am getting this error even when the symbolic link already exists. Do you think I can just ignore this error and continue with the installation, or is there something else I need to check first? -
Reading/Writing .xlsx files using Webdynpro for Java
Dear All
I have a requirement to read/write excel files in .xlsx format. I am good in doing it with .xls format using jxl.jar. The jxl.jar doesn't support .xlsx format. Kindly help me in understanding how do I need to proceed on reading/writing .xlsx files using Webdynpro for Java.
Thanks and Regards
Ramamoorthy Di am using jdk 1.6.22 and IBM WebSphere
when i use poi-3.6-20091214.jar and poi-ooxml-3.6-20091214.jar to read .xlsx file. but i am getting following errors
The project was not built since its classpath is incomplete. Cannot find the class
file for java.lang.Iterable. Fix the classpath then try rebuilding this project.
This compilation unit indirectly references the missing type java.lang.Iterable
(typically some required class file is referencing a type outside the classpath)
how can i resolve it
here is the code that i have used
public class HomeAction extends DispatchAction {
public ActionForward addpage(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
String name = "C:/Documents and Settings/bharath/Desktop/Book1.xlsx";
FileInputStream fis = null;
try {
Object workbook = null;
fis = new FileInputStream(name);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sheet = (XSSFSheet) wb.getSheetAt(0);
Iterator rows = sheet.rowIterator();
int number=sheet.getLastRowNum();
System.out.println(" number of rows"+ number);
while (rows.hasNext())
XSSFRow row = ((XSSFRow) rows.next());
Iterator cells = row.cellIterator();
while(cells.hasNext())
XSSFCell cell = (XSSFCell) cells.next();
String Value=cell.getStringCellValue();
System.out.println(Value);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fis != null) {
fis.close();
return mapping.findForward("returnjsp"); -
Dear Experts,
What is the best way to write java objects into file
1. Using Object Output Stream
or
2.Using ByteArray OutputStream
with Thanks
PanneerDear Experts,
What is the best way to write java objects into file
1. Using Object Output Stream
or
2.Using ByteArray OutputStream
with Thanks
PanneerWhat do you mean or? Because I would assume the contents of the byte array stream is coming from an ObjectOutputStream.
Or do you mean to use some sort of buffering... -
EXPORT XFA error while writing XFA files
Hello Experts,
We are facing an error while exporting to PDF from BEx report.
We are on EP7 SP14. BI on SP16.
After the report is displayed and Export to PDF button is clicked, a new window opens which shows following:
1. Error:
Message: No message was provided.
Stack trace: java.lang.NullPointerException
at com.sap.ip.bi.export.model.layout.impl.Margins.<init>(Margins.java:32)
at com.sap.ip.bi.export.model.layout.impl.CellLayout.<init>(CellLayout.java:48)
at com.sap.ip.bi.export.model.layout.impl.CellLayout.dub(CellLayout.java:57)
at com.sap.ip.bi.export.xfa.xftextensions.TableContentIterator.createCell(TableContentIterator.java:170)
at com.sap.ip.bi.export.xfa.xftextensions.TableContentIterator.next(TableContentIterator.java:104)
at com.sap.ip.bi.export.xfa.xftextensions.TableSubFormSet.writeXFD(TableSubFormSet.java:1189)
at com.sap.ip.bi.export.xfa.core.Xft_subform.writeXFD(Xft_subform.java:1604)
at com.sap.ip.bi.export.xfa.core.Xft_subform.writeXFD(Xft_subform.java:1604)
at com.sap.ip.bi.export.xfa.core.Xft_template.writeXFD(Xft_template.java:216)
at com.sap.ip.bi.export.xfa.core.Xft.writeXFD(Xft.java:62)
at com.sap.ip.bi.export.xfa.impl.Document.writeWidthsAsXmlToStream(Document.java:294)
at com.sap.ip.bi.export.xfa.widthcalc.WidthCalculator.<init>(WidthCalculator.java:55)
at com.sap.ip.bi.export.xfa.impl.SizeCalculator.calc(SizeCalculator.java:96)
at com.sap.ip.bi.export.impl.ExportController.calculateAndSetSizes(ExportController.java:626)
at com.sap.ip.bi.export.impl.ExportController.doExportPrep(ExportController.java:405)
at com.sap.ip.bi.export.impl.ExportController.convert(ExportController.java:325)
at com.sap.ip.bi.export.controller.ExportResult.createExport(ExportResult.java:71)
at com.sap.ip.bi.webapplications.pageexport.PageExportRenderingRootNode.createPDF(PageExportRenderingRootNode.java:593)
at com.sap.ip.bi.webapplications.pageexport.PageExportRenderingRootNode.doExport(PageExportRenderingRootNode.java:132)
at com.sap.ip.bi.webapplications.pageexport.PageExportRenderingRootNode.processRendering(PageExportRenderingRootNode.java:349)
at com.sap.ip.bi.webapplications.runtime.impl.Page.buildRenderingTree(Page.java:4494)
at com.sap.ip.bi.webapplications.runtime.impl.Page.processRenderingRootNode(Page.java:4568)
at com.sap.ip.bi.webapplications.runtime.impl.Page.processRendering(Page.java:4204)
at com.sap.ip.bi.webapplications.runtime.impl.Page.doProcessRequest(Page.java:4150)
at com.sap.ip.bi.webapplications.runtime.impl.Page._processRequest(Page.java:2948)
at com.sap.ip.bi.webapplications.runtime.impl.Page.processRequest(Page.java:2794)
at com.sap.ip.bi.webapplications.runtime.controller.impl.Controller.doProcessRequest(Controller.java:994)
at com.sap.ip.bi.webapplications.runtime.controller.impl.Controller._processRequest(Controller.java:883)
at com.sap.ip.bi.webapplications.runtime.controller.impl.Controller.processRequest(Controller.java:860)
at com.sap.ip.bi.webapplications.runtime.jsp.portal.services.BIRuntimeService._handleRequest(BIRuntimeService.java:359)
at com.sap.ip.bi.webapplications.runtime.jsp.portal.services.BIRuntimeService.handleRequest(BIRuntimeService.java:276)
at com.sap.ip.bi.webapplications.runtime.jsp.portal.components.LauncherComponent.doContent(LauncherComponent.java:24)
at com.sapportals.portal.prt.component.AbstractPortalComponent.serviceDeprecated(AbstractPortalComponent.java:209)
at com.sapportals.portal.prt.component.AbstractPortalComponent.service(AbstractPortalComponent.java:114)
at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328)
at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136)
at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:189)
at com.sapportals.portal.prt.component.PortalComponentResponse.include(PortalComponentResponse.java:215)
at com.sapportals.portal.prt.pom.PortalNode.service(PortalNode.java:645)
at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328)
at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136)
at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:189)
at com.sapportals.portal.prt.core.PortalRequestManager.runRequestCycle(PortalRequestManager.java:753)
at com.sapportals.portal.prt.connection.ServletConnection.handleRequest(ServletConnection.java:240)
at com.sapportals.portal.prt.dispatcher.Dispatcher$doService.run(Dispatcher.java:524)
at java.security.AccessController.doPrivileged(Native Method)
at com.sapportals.portal.prt.dispatcher.Dispatcher.service(Dispatcher.java:407)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.sap.engine.services.servlets_jsp.server.servlet.InvokerServlet.service(InvokerServlet.java:156)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:401)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:386)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:364)
at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:1039)
at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:265)
at com.sap.engine.services.httpserver.server.Client.handle(Client.java:95)
at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:175)
at
com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java
:33)
at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
at java.security.AccessController.doPrivileged(Native Method)
at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:102)
at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:172)
Message: EXPORT XFA error while writing XFA files
Stack trace: com.sap.ip.bi.base.exception.BIBaseRuntimeException: EXPORT XFA error while writing XFA files
at com.sap.ip.bi.export.xfa.impl.Document.writeWidthsAsXmlToStream(Document.java:311)
at com.sap.ip.bi.export.xfa.widthcalc.WidthCalculator.<init>(WidthCalculator.java:55)
at com.sap.ip.bi.export.xfa.impl.SizeCalculator.calc(SizeCalculator.java:96)
at com.sap.ip.bi.export.impl.ExportController.calculateAndSetSizes(ExportController.java:626)
at com.sap.ip.bi.export.impl.ExportController.doExportPrep(ExportController.java:405)
at com.sap.ip.bi.export.impl.ExportController.convert(ExportController.java:325)
at com.sap.ip.bi.export.controller.ExportResult.createExport(ExportResult.java:71)
at com.sap.ip.bi.webapplications.pageexport.PageExportRenderingRootNode.createPDF(PageExportRenderingRootNode.java:593)
at com.sap.ip.bi.webapplications.pageexport.PageExportRenderingRootNode.doExport(PageExportRenderingRootNode.java:132)
at com.sap.ip.bi.webapplications.pageexport.PageExportRenderingRootNode.processRendering(PageExportRenderingRootNode.java:349)
at com.sap.ip.bi.webapplications.runtime.impl.Page.buildRenderingTree(Page.java:4494)
at com.sap.ip.bi.webapplications.runtime.impl.Page.processRenderingRootNode(Page.java:4568)
at com.sap.ip.bi.webapplications.runtime.impl.Page.processRendering(Page.java:4204)
at com.sap.ip.bi.webapplications.runtime.impl.Page.doProcessRequest(Page.java:4150)
at com.sap.ip.bi.webapplications.runtime.impl.Page._processRequest(Page.java:2948)
at com.sap.ip.bi.webapplications.runtime.impl.Page.processRequest(Page.java:2794)
at com.sap.ip.bi.webapplications.runtime.controller.impl.Controller.doProcessRequest(Controller.java:994)
at com.sap.ip.bi.webapplications.runtime.controller.impl.Controller._processRequest(Controller.java:883)
at com.sap.ip.bi.webapplications.runtime.controller.impl.Controller.processRequest(Controller.java:860)
at com.sap.ip.bi.webapplications.runtime.jsp.portal.services.BIRuntimeService._handleRequest(BIRuntimeService.java:359)
at com.sap.ip.bi.webapplications.runtime.jsp.portal.services.BIRuntimeService.handleRequest(BIRuntimeService.java:276)
at com.sap.ip.bi.webapplications.runtime.jsp.portal.components.LauncherComponent.doContent(LauncherComponent.java:24)
at com.sapportals.portal.prt.component.AbstractPortalComponent.serviceDeprecated(AbstractPortalComponent.java:209)
at com.sapportals.portal.prt.component.AbstractPortalComponent.service(AbstractPortalComponent.java:114)
at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328)
at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136)
at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:189)
at com.sapportals.portal.prt.component.PortalComponentResponse.include(PortalComponentResponse.java:215)
at com.sapportals.portal.prt.pom.PortalNode.service(PortalNode.java:645)
at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328)
at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136)
at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:189)
at com.sapportals.portal.prt.core.PortalRequestManager.runRequestCycle(PortalRequestManager.java:753)
at com.sapportals.portal.prt.connection.ServletConnection.handleRequest(ServletConnection.java:240)
at com.sapportals.portal.prt.dispatcher.Dispatcher$doService.run(Dispatcher.java:524)
at java.security.AccessController.doPrivileged(Native Method)
at com.sapportals.portal.prt.dispatcher.Dispatcher.service(Dispatcher.java:407)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.sap.engine.services.servlets_jsp.server.servlet.InvokerServlet.service(InvokerServlet.java:156)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:401)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:386)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:364)
at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:1039)
at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:265)
at com.sap.engine.services.httpserver.server.Client.handle(Client.java:95)
at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:175)
at
com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java
:33)
at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
at java.security.AccessController.doPrivileged(Native Method)
at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:102)
at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:172)
Caused by: java.lang.NullPointerException
at com.sap.ip.bi.export.model.layout.impl.Margins.<init>(Margins.java:32)
at com.sap.ip.bi.export.model.layout.impl.CellLayout.<init>(CellLayout.java:48)
at com.sap.ip.bi.export.model.layout.impl.CellLayout.dub(CellLayout.java:57)
at com.sap.ip.bi.export.xfa.xftextensions.TableContentIterator.createCell(TableContentIterator.java:170)
at com.sap.ip.bi.export.xfa.xftextensions.TableContentIterator.next(TableContentIterator.java:104)
at com.sap.ip.bi.export.xfa.xftextensions.TableSubFormSet.writeXFD(TableSubFormSet.java:1189)
at com.sap.ip.bi.export.xfa.core.Xft_subform.writeXFD(Xft_subform.java:1604)
at com.sap.ip.bi.export.xfa.core.Xft_subform.writeXFD(Xft_subform.java:1604)
at com.sap.ip.bi.export.xfa.core.Xft_template.writeXFD(Xft_template.java:216)
at com.sap.ip.bi.export.xfa.core.Xft.writeXFD(Xft.java:62)
at com.sap.ip.bi.export.xfa.impl.Document.writeWidthsAsXmlToStream(Document.java:294)
2. Message:
No metadata is available for "DISABLE_NAVIGATION":
<parameterList>
<param name="BI_COMMAND_TYPE" value="OPEN_DIALOG_DISABLE_NAVIGATION"/>
<param name="TARGET_DIALOG_REF" value="DISABLE_NAVIGATION"/>
</parameterList>
In this window, complete screen of report is displayed as an image instead of PDF.
Please let me know if anybody faced similar issue earlier.
It was working perfect earlier, but suddenly error started.
regards
Kedar KulkarniNo proper findings, but issue resolved.
Problem i found that we got a domain change and service values were not refreshed until we apply new patch.
So when we applied patch level 6 on BI WEBAPP& BI BASE S URL for ADS got refreshed and we faced the issue.
After resetting the URL to new domain problem got resolved.
Regards
Kedar Kulkarni -
Hi,
I have made a program that reads a string, converts it to bytes, then writes to a file.
Well i got the first two working, but its not writing to file. I know it should work cos i have written to file on my previous tests, but when i used a FOR loop it stoped working. Do ya know why. Below is the code...
for (int a = 0;a = bytes.length - 1;a++){
of.write(bytes[a]);
System.out.print(" " + bytes[a] + " : " + bytes.length);
My friend told me to use bytes.length - 1 as it is meant to stop the OUTOFBOUNDS error.
OK,
my regards
Below is the whole program, its a bit messy cos i got lots of old code that i have blocked.
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.String;
public class sender implements Runnable {
int i= 0;
String mes;
int count =0;
int b = 0;
boolean yes = false;
public static void main (String[] arguments) {
Thread th = new Thread (new sender());
th.start ();
//sender();
//while (true){}
public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
String mesdialog = JOptionPane.showInputDialog(null,
"Enter your message");
mes = mesdialog.toString();
try {
//FileOutputStream of = new
//FileOutputStream ("send.txt");
FileWriter of = new
FileWriter("send.txt");
//BufferedReader in = new
// BufferedReader(fr);
//while (true){}
int i = 66;
boolean eof = false;
int inChar = 0;
//String inChar;
byte[] bytes = mes.getBytes();
/* < disable / enable
do {
int n=Integer.MIN_VALUE;
try{
n = Integer.parseInt(mes);
} catch (NumberFormatException nfe){
//inChar = n;
if (inChar != -1) {
byte outChar = (byte)inChar* ;
//char outChar = (char)inChar ;
of.write(outChar);
System.out.println("" + outChar);
//of.write(mes,0,20);
} else
eof = true;
} while (!eof);//*/
for (int a = 0;a = bytes.length - 1;a++){
of.write(bytes[a]);
System.out.print(" " + bytes[a] + " : " + bytes.length);
while (!yes) {
if (bytes[b] == 32 )
yes = true;
else {
of.write(bytes);
System.out.print(" " + bytes[b]);
b++;
//System.exit(0);
//outfile.write(input);
} catch (IOException e) {
System.out.print("AAA ERROR");}your friend was obviously wrong.
for (int a = 0;a = bytes.length - 1;a++){ // that does nothing
of.write(bytes[a]);
System.out.print(" " + bytes[a] + " : " + bytes.length);
}the above "for" loop says :
1:initialize a with 0;
2:do loop while a=bytes.length(<-that's completely wrong. it should be
a boolean expression);
3:for each loop increment "a" by one.
try this:for (int a = 0;a < bytes.length;a++){
of.write(bytes[a]);
System.out.print(" " + bytes[a] + " : " + bytes.length); -
public static void main(String args[]) throws Exception
String str1;
int length;
BufferedReader inpu=new BufferedReader(new InputStreamReader(System.in));;
System.out.println("Enter something: ");
str1=inpu.readLine();
System.out.println("hai"+" "+str1);
i ve used the above code to read an input from the user now i want to write this to a file.plz tell me how to do itya i tried using FileWriter
But is there any other methods
import java.io.*;
class readtofile
public static void main(String args[]) throws Exception
String str1;
int length;
//stream given to inputstream reader then buffered usin buffered reader
BufferedReader inpu=new BufferedReader(new InputStreamReader(System.in));;
System.out.println("Enter something: ");
str1=inpu.readLine();
System.out.println("hai"+" "+str1);
//opening a new file for output
File outfile_1= new File("testout.txt");
//using filewriter class for writing to file
FileWriter out= new FileWriter(outfile_1);
out.write(str1);
out.close();
} -
Writing to file with ObjectOutputStream
ApartmentWriterProgram asks information about apartments
and saves it to a file.
For some reason it doesnt save information, it writes:
Writing to file "+file+ " failed.
So there happens IOException in the method write(Apartment apartment).
Or in the run().
I dont know what's wrong. Do you?
public class ApartmentFileHandler extends Object implements Serializable {
private OutputStream outStream;
private ObjectOutputStream obStream;
private String filePath;
public ApartmentFileHandler(String filePath) {
this.filePath = filePath;
/** Writes the given apartment data in the file. If the file already
exists, the old contents are overwritten.
Parameters:
apartment - the apartment to be written in the file
Throws:
IOException - if other problems arose when handling the file (e.g. the
file could not be written)
public void write(Apartment apartment)
throws IOException {
outStream = new FileOutputStream(filePath);
obStream = new ObjectOutputStream(outStream);
obStream.writeObject(apartment);
import java.io.*;
import java.util.*;
public class ApartmentWriterProgram
extends Object
private KeyboardReader keyboardReader;
private List roomsInList;
private Room[] rooms;
private int numberOfRooms;
private String file;
public ApartmentWriterProgram()
this.keyboardReader = new KeyboardReader();
this.roomsInList = new ArrayList();
this.rooms = new Room [numberOfRooms];
/** Runs the writer program. The program asks the user for some
apartment data and a file name, and saves the data in the file. */
public void run() {
try {
numberOfRooms = keyboardReader.getInt("Give number of rooms: ");
for (int i =1; i<numberOfRooms+1; i++) {
String type =keyboardReader.getString("Give " +i+ ". " + "type of the room: ");
double area =keyboardReader.getDouble("Give " +i+ ". " + "area of room: ");
Room room= new Room(type, area);
this.roomsInList.add(huone);
roomsInList.toArray(rooms);
Apartment apartment = new Apartment(rooms);
System.out.println();
file = keyboardReader.getString("Give name of the file: ");
ApartmentFileHandler handler = new ApartmentFileHandler(file);
handler.write(apartment);
} catch (IOException ioe) {
System.out.println("Writing to file "+file+ " failed.");
public static void main(String[] args) {
ApartmentWriterProgram program = new ApartmentWriterProgram();
program.run();
}There is nothing to gain in not putting the throws IOException in the write method, since the exception object will have the information about the actual problem.
Is this a typo for the this post? this.roomsInList.add(huone); should be room nes pas.
What exception is actually thrown? To find out useSystem.out.println("Exception: " + ioe);Then wonder why you have the AppartmentFileHandler implement Serializable when you are not writing that object to the file. -
Hai,
I am installing Oracle9.2.0 on my RH8.0 system. I got an error like this after running runInstaller: Error in writing to file: .../oracle/jre/1.3.1/bin/i386/native_threads/java
Someone know a solution for this ?
thx
rameshYour error has been completely addressed here http://www.puschitz.com/InstallingOracle9i.html. This is very informative. You may want to check this out before proceeding. The straight solution to this is when this error shows up, leave it open, find the native_threads/java file from the CD to the directory Oracle is asking for this. I had this problem and it turned out when I extracted and burnt it to a CD, it didn't copy the native_threads directory and others, so you want to check this as well.
Del -
What the program is supposed to do
Print the squares of one through ten to a file whose name is typed in by the user.
My Program
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class SquareSend
private JTextField field;
public static void main(String[] args)
SquareSend gui = new SquareSend();
gui.go();
public void go()
JFrame frame = new JFrame();
JTextField field = new JTextField();
field.addActionListener(new sendToFile());
frame.getContentPane().add(BorderLayout.CENTER, field);
frame.setSize(300, 50);
frame.setVisible(true);
public class sendToFile implements ActionListener
public void actionPerformed(ActionEvent e)
FileOutputStream out;
PrintStream p;
try
out = new FileOutputStream(field.getText());
p = new PrintStream( out );
int x = 1;
while (x<11)
int y = (int)(Math.pow(x,2));
p.println("The square of "+x+" is "+y+".");
x++;
p.close();
catch (Exception f)
System.err.println ("Error writing to file");
Error Message
Error writing to file (display message if designated in the try...catch statement).
Thanks for your helpuse f.printStackTrace() in your catch clause if you want more information about the exception thrown.
-
Problems while writing to file
Hi,
I'm trying to query my test database (mysql) and to write these results to a file, I manage to get the results out of the database, but when I try to write for instance an int to a file, the file replaces the int by a square. What can be wrong?? The file is created successfully and I've writen the int to the standard out before writing it to the file; in the standard out the int is correct.
code:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class getData extends HttpServlet {
FileWriter fw;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter();
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch(Exception e){
System.err.println("Database driverclass not found");
Connection conn;
//insert values into DB
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=admin12&password=adm12");
Statement stmt = conn.createStatement();
String slq = "Select * from feedback";
ResultSet rs = stmt.executeQuery(slq);
if (rs==null){System.out.println("nOT OK");}
else{
try{
File f = new File("D:\\mysql\\Data.txt");
fw = new FileWriter(f);
while(rs.next())
writeToFile(rs.getString(1));
writeToFile(rs.getString(2));
writeToFile(rs.getInt(3));
writeToFile(rs.getInt(4));
writeToFile(rs.getString(5));
writeToFile(rs.getInt(6));
catch(IOException e)
System.out.println("Error occured while writing to file");
stmt.close();
conn.close();
} catch(SQLException sqle){
System.err.println("A SQL error has occured: " + sqle.getMessage());
/* output your page here*/
out.println("<html>");
out.println("<head>");
out.println("<title>getDataServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h2>Data recovered</h2>");
out.println("</body>");
out.println("</html>");
out.close();
fw.flush();
fw.close();
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
processRequest(request, response);
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
processRequest(request, response);
/** Returns a short description of the servlet.
public String getServletInfo() {
return "Short description";
private void writeToFile(int i)
try{
System.out.println("test: "+i);
fw.write(i);
fw.write(";");
}catch(IOException e1)
private void writeToFile(String str)
try{
if (str!=null&&(str.equals("null")==false)){
fw.write(str);
fw.write(";");
}catch(IOException e2)I would imagine that FileWriter is writing the byte value to the file. Just change your SQL get to this writeToFile(rs.getString(6)); and write it as a String instead of an int.
DesQuite -
Multithreading - writing to file
How can I get to write the Thread name, date and time to a file with the same thread name?
What would I need to do to write the same information 1000 times to the file? Thank you.
import java.lang.Thread;
import java.lang.InterruptedException;
public class RiveraThreadsMain {
public static void main(String[] args) {
System.out.println("Creating threads");
Thread riverathread0 = new Thread (new RiveraThreads ("riverathread0"));
Thread riverathread1 = new Thread (new RiveraThreads ("riverathread1"));
Thread riverathread2 = new Thread (new RiveraThreads ("riverathread2"));
System.out.println("Threads created, starting tasks.");
riverathread0.start(); // invokes thread1's run method
riverathread1.start(); // invokes thread2's run method
riverathread2.start(); // invokes thread3's run method
try
Thread.currentThread() .sleep (10000);
catch (InterruptedException e)
e.getStackTrace();
System.out.printf (
"terminated prematurely due to interruption");
System.out.println("Tasks started, main thread ends. \n");
} // end main
import java.io.File;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.FileNotFoundException;
import java.util.Formatter;
import java.util.NoSuchElementException;
import java.util.Calendar;
import java.util.Scanner;
public class RiveraThreads implements Runnable {
Thread launcher;
private String taskName;
private Scanner input;
private Formatter output;
// empty constructor
public RiveraThreads (){
public RiveraThreads (String threadName)
launcher = new Thread ( this, threadName );
System.out.println ( launcher.getName());
launcher.start();
// taskName = name; // set task name
public void run ()
//System.out.println(Thread.currentThread().getName());
try
Calendar dateTime = Calendar.getInstance();
// output = new Formatter (new File (launcher.getName() ));
input = new Scanner( new File( launcher.getName() ) );
output = new Formatter (new File ( launcher.getName() ));
System.out.printf( launcher.getName() + "%tc\n", dateTime );
}// end try
catch ( NoSuchElementException exception)
exception.getStackTrace();
System.out.printf ( "%s %s \n ", taskName,
"terminated prematurely due to interruption");
}// end catch
catch ( FileNotFoundException filenotfound )
System.out.printf (" %s %s \n ", filenotfound,
"File not found");
catch (IOException ioexception)
System.err.printf(
"Unable to read file");
// close file and terminate application
public void closeFile()
input.close();
}// close file
output.close();
} // end method closeFile
}FRiveraJr wrote:
Hi jverd
What are you having trouble with?
I know how to use the BufferedReader and BufferedWriter for opening, reading and writing to file. But the trouble consists in a lot of code to write and how will I call the appropriate file name since it is supposed to be
the same name as the thread into all of this? I still don't know what problem you're having.
You know how to provide a file name, right?
Do you know how to get a thread name?
If both are "yes", then I don't see what's left that you'd be having problems with. You need to be specific. Nobody here can read your mind, since it's the holidays.
Writing to a file?
Yes, I'm getting the correct results to the console with the thread name and the calendar option with the date and time and this is the data that needs to be written to a file. Isn't there a more simple way?A simpler way than your current code? How can anybody answer that without seeing your code?
What would I need to do to write the same information 1000 times to the file?
Because that is part of the requirements. Is not that I am insane :0).... This is just part of developing my skills since I'm new to all this. So, do you still have a question about this part? You do know how to loop, right? If not, you shouldn't be getting anywhere near I/O or multithreading. -
Error in writing to file encountered while applying patch 9.2.0.8
Hi,
I encountered the error message below while applying Oracle 9.2.0.8 patch set using OUI on server running Oracle 9.2.0.7 and Windows 2003 Enterprise Edition SP2:
Error in writing to file 'C:\oracle\ora92\BIN\orapls9.dll'
[C:\oracle\ora92\BIN\orapls9.dll (he process cannot access
the file because it is being used by another process)]
I've already stopped the Oracle instance and services before invoking the setup.exe.
My question is: Why this is happening and what is the resolution to prevent this error from happening?I used the script in the Metalink note 454040.1 and chose 5. I typed in the orapls9.dll to see which module is locking this dll and I found out it is avrrepsvc.exe which is one of the services our application is running. I just stopped it in Services Console and run the setup.exe of the patch. The installaton of patch run successfully. I checked the version using 'select banner from v$version' and I now got this results:
SQL> select banner from v$version;
BANNER
Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
PL/SQL Release 9.2.0.8.0 - Production
CORE 9.2.0.8.0 Production
TNS for 32-bit Windows: Version 9.2.0.8.0 - Production
NLSRTL Version 9.2.0.8.0 - Production
I have a related question. When checking from dba_registry, isn't it that versions of components should have been upgraded too? Please see below I what got:
SQL>SELECT SUBSTR(comp_id,1,15) comp_id, status, SUBSTR(version,1,10)
version, SUBSTR(comp_name,1,30) comp_name
FROM dba_registry ORDER BY 1;
COMP_ID STATUS VERSION COMP_NAME
CATALOG VALID 9.2.0.7.0 Oracle9i Catalog Views
CATJAVA VALID 9.2.0.7.0 Oracle9i Java Packages
CATPROC VALID 9.2.0.7.0 Oracle9i Packages and Types
CONTEXT VALID 9.2.0.7.0 Oracle Text
JAVAVM VALID 9.2.0.7.0 JServer JAVA Virtual Machine
ORDIM VALID 9.2.0.7.0 Oracle interMedia
OWM VALID 9.2.0.1.0 Oracle Workspace Manager
SDO VALID 9.2.0.7.0 Spatial
XDB VALID 9.2.0.7.0 Oracle XML Database
XML VALID 9.2.0.9.0 Oracle XDK for Java
10 rows selected.
What tasks did I missed int the steps?
ADDITION:
It looks like I forgot to run the catpatch.sql and utlrp.sql.
Edited by: user5470917 on Jun 19, 2009 2:52 PM -
What is causing the failure of the Oracle JDBC Development Drivers component during the Oracle9i installation, I'm getting the
Error in writing to file classes111_g.jar
If I skip this component then it keep on listing other files including a file.PDF file and I checked all the permissions so it is not a file permission error.
Could someone list the steps they took to set up JAVA on their Linux box and then what you had to add exactly to your ".bash_profile"
Perhaps this is what I'm doing wrong.
Thnx.
JarLoc = /tmp/OraInstall2002-10-11_11-17-22PM/temp31
gpEntries = [[classes111_g.zip ->%ORACLE_HOME%/jdbc/lib/classes111_g.zip 1381728 plats=1=>[46] langs=1=>[en]]
, [classes111_g.jar ->%ORACLE_HOME%/jdbc/lib/classes111_g.jar 1371600 plats=1=>[46] langs=1=>[en]]
DllGroup = false
Exception thrown from action: copyGroupFromJar
Exception Name: IOException2
Exception String: Error in writing to file /ora1/app/oracle/product/9.2.0/jdbc/lib/classes111_g.jar
Exception Severity: 2
Exception handling set to prompt user with options to RETRY
User choice : Retry
Exception thrown from action: copyGroupFromJar
Exception Name: IOException2
Exception String: Error in writing to file /ora1/app/oracle/product/9.2.0/jdbc/lib/classes111_g.jar
Exception Severity: 2Your error has been completely addressed here http://www.puschitz.com/InstallingOracle9i.html. This is very informative. You may want to check this out before proceeding. The straight solution to this is when this error shows up, leave it open, find the native_threads/java file from the CD to the directory Oracle is asking for this. I had this problem and it turned out when I extracted and burnt it to a CD, it didn't copy the native_threads directory and others, so you want to check this as well.
Del -
Why Writing a File Cost Such a Memory?
As a test case I tried the next code on my Mac OS X 10.2.3:
import java.io.*;
public class WriteZero {
public static void main(String[] args) throws Exception{
java.io.BufferedOutputStream bs = new java.io.BufferedOutputStream(new FileOutputStream("zeros"));
int mb=1024*1024;
int mb500 = mb*500;
try{
int k=0;
while((1==1)){
bs.write(0x0);
k++;
if(k%mb==0){
Thread.sleep(200);//inessential but enables to work in the back ground
System.gc();// tries to free memory
}else if(k>mb500) break;//50mb
}catch(InterruptedException ie){;
}catch(java.lang.Throwable th){
System.err.println(th.toString());
}finally{
if(bs!=null) bs.close();
}This simply writes the size of 500MB of the characters '\u0000.' In the course of writing the free RAM decreases monotonously until it reaches around 6 MB of free memory, recording 919 pageouts. The number 919 of pageouts is very rare on my OS, which has 512MB of RAM. What causes this consumption of memory in simple writing a file?Something up with either your VM or VM configuration maybe? I just copied and pasted your code, and it's cruising at just under 6MB - which means maybe 2 MB allocated in heap space.
Verbose:gc indicates that full garbage collections are being done about every second, but that the heap is a stable size.
Check your max and min heap-sizes, and also try it on a different VM if you can - there's no reason for this program to blow up memory that way. Also should be no need to call GC at all.
Maybe you are looking for
-
I have LR 5. When I'm in the book module and select the option to "Send Book to Blurb" i get an error message saying "The file does not have a program associated with it for performing this action. Please install a program, or if one is already ins
-
Remote 2 no longer allows direct access to chapters?
One of the coolest features of the original Remote app was how I could play a movie on my ATV, go to "now playing" on the iPhone, tap to flip the cover art over, and tap on a chapter title to jump the movie directly to that chapter. If I do the same
-
Down payments - Delivery related billing
Hi Guys, I am an FI guy. I have a question in SD billing. Is it possible to collect and clear down payments in delivery related billing. If so, Can you please elaborate the steps in doing so. Thanks, Satya
-
Hi, I am fairly new to both iDvd and Imovie. I have a .avi file 700 MB that I want to burn to dvd with iDvd so I can play it on my DVD player. When I try to import this file to a basic iDvd project I end up with a project over 8 Giga bytes, wich of c
-
Driver install don't detect Labview 2013
Hello, After installing Labview 2013 (32bits) , installing driver (Daqmx,etc...) (DVD feb.2013) , application driver don't detect labview 2013, and doesn't want install anything. Do you know this problem ? and how can i fix ? Thanks. Ludovic Windows